在Linux上编译的程序没有在#ifdef部分获取代码(Program compiled on Linux not getting code in #ifdef section)

编程入门 行业动态 更新时间:2024-10-28 14:27:32
在Linux上编译的程序没有在#ifdef部分获取代码(Program compiled on Linux not getting code in #ifdef section)

我有一个我正在研究的跨平台程序,它有几个文件

#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.0

I have a cross platform program I am working on that has several files with

#ifdef WIN32 ...inclues #endif #ifdef LINUX ..inlcudes #endif

when 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.

更多推荐

本文发布于:2023-08-01 01:58:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1350488.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   程序   ifdef   Linux   section

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!