Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 671 characters in body
Source Link
Some programmer dude
  • 411.4k
  • 36
  • 420
  • 655

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 #include directives) is really a separate step that is run before the actual compiler sees the source.

Also, when toyyou define a macro with #define, 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. pkg-config to get both compiler and linker flags. First of all you only need the compiler flags (the --cflags argument) when actually compiling your source files into object files. Then when linking you need only the linker flags (the --libs flag to pkg-config), 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).

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 #include directives) is really a separate step that is run before the actual compiler sees the source.

Also, when toy define a macro with #define, 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.

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 #include directives) is really a separate step that is run before the actual compiler sees the source.

Also, when you define a macro with #define, 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. pkg-config to get both compiler and linker flags. First of all you only need the compiler flags (the --cflags argument) when actually compiling your source files into object files. Then when linking you need only the linker flags (the --libs flag to pkg-config), 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).

Source Link
Some programmer dude
  • 411.4k
  • 36
  • 420
  • 655

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 #include directives) is really a separate step that is run before the actual compiler sees the source.

Also, when toy define a macro with #define, 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.