[英]Linking library in makefile
i have problem with linking libraries boost and curl in my simple makefile. 我在简单的makefile中链接库boost和curl时遇到问题。 When i use single command: 当我使用单个命令时:
g++ -I /usr/lib/boost/include -L /usr/lib/boost/lib website.cpp website.h main.cpp data.cpp data.h -lboost_regex -lcurl
everything is ok but when i use makefile 一切都很好,但是当我使用makefile时
a.out: website.o data.o main.o
g++ -L /usr/lib/boost/lib -lboost_regex website.o data.o main.o -o a.out -lcurl
data.o: data.cpp data.h
g++ -c data.cpp -o data.o
website.o: website.cpp website.h
g++ -I /usr/lib/boost/include -c website.cpp -o website.o
main.o: main.cpp
g++ -c main.cpp -o main.o
i have a lot of errors: 我有很多错误:
g++ -c main.cpp -o main.o
g++ -L /usr/lib/boost/lib -lboost_regex website.o data.o main.o -o a.out -lcurl
website.o: In function boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char const*, char const*, unsigned int)':
website.cpp:(.text._ZN5boost11basic_regexIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE6assignEPKcS7_j[boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char const*, char const*, unsigned int)]+0x22): undefined reference to `boost::basic_
I use boost and curl in website.cpp (of course headlines are in website.h). 我在website.cpp中使用boost和curl(当然,标题在website.h中)。
The problem is that -lboost_regex
is being placed before .o
s in the compiler command, unlike your single command which has -lboost_regex
at the end. 问题在于, -lboost_regex
在编译器命令中位于.o
之前,这与您的单个命令末尾带有-lboost_regex
命令不同。
Change: 更改:
g++ -L /usr/lib/boost/lib -lboost_regex website.o data.o main.o -o a.out -lcurl g ++ -L / usr / lib / boost / lib -lboost_regex website.o data.o main.o -o a.out -lcurl
to: 至:
g++ -L/usr/lib/boost/lib website.o data.o main.o -o a.out -lcurl -lboost_regex g ++ -L / usr / lib / boost / lib website.o data.o main.o -o a.out -lcurl -lboost_regex
See GCC Link Options for explanantion of why the order matters. 有关订单为何重要的说明,请参见GCC链接选项 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.