Makefile define

Hi everyone,

How to set a define in the makefile that recognizes in the code? Like this:

in my Makefile:

LINUX=1

in the code:

#ifdef LINUX
#include <gdkx.h>
#endif

Thanks...
Paulo
I assume you are using the GCC?

The GCC takes as command argument macros

g++ -Wall myprog.cpp -DFOOEY=42

This will compile myprog.cpp as if it had a #define FOOEY 42 as the first line in the file.


You can use variables in a makefile. Unfortunately, makefiles are not very cross-platform capable because they rely upon the active command shell to process the make instructions (the tab-indented lines following a rule).

GNU Make online reference:
http://www.cs.utah.edu/dept/old/texinfo/make/make_toc.html



HOWEVER, compilers typically auto-define macros to identify the OS to you. For example, if you are compiling on Linux, you can know it without any effort on your part other than simply checking:
1
2
3
#if defined(linux) || defined(__linux)
  #include <gdkx.h>
#endif 

You can look stuff up at the amazingly cool Pre-defined C/C++ Compiler Macros website:
http://predef.sourceforge.net/

Hope this helps.
Thanks a lot! That's what I needed...
Hi,
I have a complex project (100 source files) and I have a make file from the format
SRCS= a.cpp b.cpp .....
%.o : %.c
gcc -c -MD -o $@ $<
@cp $*.d $*.P; \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \
rm -f $*.d
However, I receceive a compilation error :
In a.cpp: error no matching function for call to b::foo(int&)
candidates are: b::foo(int)

Is this is a linking problem ?
No, you are most likely trying to pass a constant value to a function taking a (non-const) reference. See if you have a line "b::foo(5)" or something like that anywhere.

BTW, it is not very polite tho hijack someones post like this. If you still have problems please create a new topic.
10X for your reply. (i didnt find how to create a new topic).
However, my problem is exactly the opposite. I'm trying to pass a value to a function who's signature is : void b::foo(int i);
and the function call: int j=8;
b::foo(j);

According to the compiler the function call is ::
b::foo(int&)
and the candidate : b::foo(int)
The code do compile in visual studio, but not in linux!
Topic archived. No new replies allowed.