Makefile 不使用包含/库路径?
好吧,经过 3 个小时的研究,我快要疯了,所以我想是时候把它传递给一些新的眼睛了。
CXXFLAGS = -g -Wall
OBJS = main.o
PROG = test
INCLUDES = -I /usr/include/mysql -I /usr/local/include
LIBS = -L /usr/lib/mysql -l libmysqlclient.so.15.0.0 -L /usr/local/lib -l libmysqlpp.so.3.1.0
all: $(PROG)
${PROG}: $(OBJS)
$(CXX) $(INCLUDES) -o $(PROG) $(OBJS) $(LIBS)
clean:; $(RM) -f $(PROG) core *.o
包含路径有问题,因为当 /usr/include/mysql 中明确存在 mysql_version.h 时,我收到不存在 mysql_version.h 的错误。
检查输出的第一部分,它说
g++ -g -Wall -c -o main.o main.cpp
这让我认为我在 Makefile 中格式化了错误的内容(由于额外的空格和缺少包含/库路径)。但是,我查看了数十本有关 Makefile 和 g++ 选项的手册和文章,但……没有任何进展。
我认为这应该是一个简单的修复。拜托,请帮忙(你感觉到我的绝望了吗?)。
另一方面,您认为有必要专门指定库吗?我让这些东西在 XCode 中运行得很好,但我正在尝试将代码迁移到我的网络服务器...... Makefile 已经停止了所有进展,我认为这是我应该学习的东西。
Well, after 3 hours of researching, I'm about to go insane, so I figure it's time to pass it off to some new eyes.
CXXFLAGS = -g -Wall
OBJS = main.o
PROG = test
INCLUDES = -I /usr/include/mysql -I /usr/local/include
LIBS = -L /usr/lib/mysql -l libmysqlclient.so.15.0.0 -L /usr/local/lib -l libmysqlpp.so.3.1.0
all: $(PROG)
${PROG}: $(OBJS)
$(CXX) $(INCLUDES) -o $(PROG) $(OBJS) $(LIBS)
clean:; $(RM) -f $(PROG) core *.o
There's something wrong with the include paths, because I get errors that mysql_version.h does not exist when it clearly does exist in /usr/include/mysql.
Checking the first part out of the ouput, it says
g++ -g -Wall -c -o main.o main.cpp
which makes me think that I've formatted something in the Makefile wrong (due to the extra spaces and lack of include/library paths). However, I've looked at dozens of manuals and articles on Makefiles and the g++ options and... no progress.
I assume this should be a simple fix. Please, please help (do you sense my despair?).
On another note, do you think specifying the library specifically is necessary? I had this stuff running in XCode just fine, but I'm trying to migrate the code to my web server... the Makefile has stopped all progress, and I figure it's something I should learn from.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 makefile 中,您已将 include 指令添加到链接阶段,而不是编译阶段。
这些行
表示通过调用 ${CXX} 中的编译器并传递包含文件夹(以及其他参数),从 ${OBJS} 中的目标文件创建 ${PROG} 中的程序。相反,对于您的变量部分,请执行以下操作:
这样您的 CXXFLAGS(用于编译阶段)现在应该拾取您的包含指令。
In your makefile, you have added your include directives to the linking stage, not the compiling stage.
The lines
Say to make the program in ${PROG} from object files in ${OBJS} by calling the compiler in ${CXX} passing the include folders (along with your other arguments). Instead, for your variable section, do this:
This way your CXXFLAGS (which are used for the compile stage) should now pickup your include directives.