我有一个我正在研究的跨平台程序,它有几个文件
#ifdef WIN32 ...inclues #endif #ifdef LINUX ..inlcudes #endif当我在LINUX上编译时,我不断发现错误没有找到函数等等,但是如果我注释掉了#ifdef LINUX块(仍然保持包含未注释的)它可以工作,所以它接缝好像我的定义不能正常工作。
这是我的make文件(文件名已更改):
CC = gcc CPP = g++ CFLAGS = -DLINUX $(INCLUDES) -c -g -O0 -Wall -fpic INCLUDES = -I. LFLAGS += -fpic -shared LFLAGS += -lpthread CFILES = a.c b.c c.c d.c e.c f.cpp g.cpp h.cpp i.cpp ##all: $(SFILES:.s=.s.o) $(CFILES:.c=.o) $(CFILES:.cpp=.o) ## $(CPP) $(INCLUDES) $(LFLAGS) -o libclient.so.1.0 $(CFILES:.c=.o) $(CFILES:.cpp=.o) all: $(SFILES:.s=.s.o) $(CFILES:.c=.o) $(CPP) $(INCLUDES) $(LFLAGS) -o libclient.so.1.0 $(CFILES:.c=.o) %.o : %.c $(CPP) -c $(CFLAGS) $< -o $@ %.o : %.cpp $(CPP) -c $(CFLAGS) $< -o $@ clean: rm *.o libclient.so.1.0I have a cross platform program I am working on that has several files with
#ifdef WIN32 ...inclues #endif #ifdef LINUX ..inlcudes #endifwhen I went to compile on LINUX I keep getting errors about not finding functions and such, but if i comment out the #ifdef LINUX blocks (still keeping the includes uncommented) it works, so it seams as if my define is not working properly.
This is my make file (file names changed):
CC = gcc CPP = g++ CFLAGS = -DLINUX $(INCLUDES) -c -g -O0 -Wall -fpic INCLUDES = -I. LFLAGS += -fpic -shared LFLAGS += -lpthread CFILES = a.c b.c c.c d.c e.c f.cpp g.cpp h.cpp i.cpp ##all: $(SFILES:.s=.s.o) $(CFILES:.c=.o) $(CFILES:.cpp=.o) ## $(CPP) $(INCLUDES) $(LFLAGS) -o libclient.so.1.0 $(CFILES:.c=.o) $(CFILES:.cpp=.o) all: $(SFILES:.s=.s.o) $(CFILES:.c=.o) $(CPP) $(INCLUDES) $(LFLAGS) -o libclient.so.1.0 $(CFILES:.c=.o) %.o : %.c $(CPP) -c $(CFLAGS) $< -o $@ %.o : %.cpp $(CPP) -c $(CFLAGS) $< -o $@ clean: rm *.o libclient.so.1.0最满意答案
您的make文件实际上适用于c文件,但不适用于c ++文件。
这是因为您为c编译调用了自定义编译命令行,但是您的cpp文件直接进入了实际上没有指定编译标志的链接命令行。
Your make file actually does work for c files, but not for c++ files.
This is because you invoke your custom compile command line for c compilation but your cpp files are going directly into what is effectively your link command line which does not specify compilation flags.
更多推荐
发布评论