My project must be C++. I include:
- pylon (C++)
My other question brought me further.
Can I make
private so that no other source file wont EVER
be able to use the private defines
Answered: yes, in C or cpp files (while their headers don’t expose those defines)
Do I have to include all libraries twice (for both compiler: GCC C, GCC C++) ? (I will be using C libraries in cpp files)
. And also for the linker ?
I’m using `pkg-config –cflags –libs glib-2.0 gtk+-2.0`
to fix some fatal errors of “file not found”
. But I still get them (e.g. glibconfig.h ~ file not found). Is there a foolproof fix for that ?
Might the problem be that if I make a global
or something and then the included libraries that might
have same define names bug around in my project ?
I started the project step by step including one library at a time and fixing issues if some arose. Then include next library and fix issues etc. I’m using eclipse, I have include guards and mixed c and cpp source files.
The only way to make a preprocessor macro “private” is to define them in a source file. Then they will be available only to that source file.
You have to remember that the preprocessor (which handles macros and
directives) is really a separate step that is run before the actual compiler sees the source.
Also, when you define a macro with
, it’s not actually defined in the same way the compiler and linker means it. After the preprocessor stages has run, there are no more macro names in the resulting translation unit.
You might want to read about translation units
, and learn how the preprocessor and compiler works.
For your second point, you’re not actually building your project twice only once and only with the C++ compiler. So you should only specify the libraries once, when linking your project.
You should also be careful when using e.g.
to get both compiler and linker flags. First of all you only need the compiler flags (the
argument) when actually compiling your source files into object files. Then when linking you need only the linker flags (the
), and the resulting flags should be places last on the command line (because the linker wants libraries after the object files that depends on the libraries).