cplusplus.com cplusplus.com
cplusplus.com   C++ : Forums : UNIX/Linux Programming : Makefile define
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Forums
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Articles
Lounge
Jobs

-

question  Makefile define

pfsmorigo (2)
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
|
Duoas (1458)
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.
|
pfsmorigo (2)
Thanks a lot! That's what I needed...
|
kerenLinux (2)
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 ?
|
exception (292)
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.
|
kerenLinux (2)
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!
|

This topic is archived - New replies not allowed.
Home page | Privacy policy
© cplusplus.com, 2000-2008 - All rights reserved - v2.2
Spotted an error? contact us