未定义的引用与boost当我试图编译
undefined reference with boost when I try to compile
当我尝试用boost编译我的服务器时,我有很多错误。这是我的makefile:
NAME = serveur
SRCS = Serveur/main.cpp
Serveur/Client.cpp
Serveur/Commande.cpp
Serveur/My_exception.cpp
Serveur/Network.cpp
Serveur/Server.cpp
#####################################################
OBJS = $(SRCS:.cpp=.o)
CC = g++
RM = rm -f
CFLAGS = -g -W -Wall -Werror
INCL = ./Serveur/boost_1_47_0
LIB = ./Serveur/boost_1_47_0/stage/lib/
NLIB = -lboost_system -lboost_system-mt -lboost_filesystem -lboost_filesystem-mt
#####################################################
$(NAME) : $(OBJS)
@$(CC) $(OBJS) -I$(INCL) -L$(LIB) $(NLIB) -o $(NAME)
@printf "n 33[33m[Message] 33[39m Compilation under Linux donenn"
.cpp.o :
@$(CC) $(CFLAGS) -I$(INCL) -L$(LIB) $(NLIB) -c $< -o $@
@printf " 33[34m[Compilation] 33[39m %sn" $<
re : fclean all
all : $(NAME)
clean :
@$(RM) *~ $(OBJS)
@printf " 33[31m[Delete] 33[39m%sn" $(OBJS)
fclean : clean
@$(RM) $(NAME)
@printf "n 33[31m[Delete] 33[39m%snn" $(NAME)
在"谷歌"后,我发现有必要把-lboost_filesystem
,但它不工作了,有下一个错误:
Serveur/main.o: In function `__static_initialization_and_destruction_0':
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
Serveur/main.o: In function `error_code':
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:315: undefined reference to `boost::system::system_category()'
Serveur/main.o: In function `boost::asio::error::get_system_category()':
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/asio/error.hpp:216: undefined reference to `boost::system::system_category()'
Serveur/Client.o: In function `__static_initialization_and_destruction_0':
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
Serveur/Network.o: In function `__static_initialization_and_destruction_0':
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
Serveur/Server.o: In function `__static_initialization_and_destruction_0':
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
/home/abad_a//rendulocal/tech3/cpp/babel-2014-abad_a/Serveur/./Serveur/boost_1_47_0/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
collect2: ld returned 1 exit status
make: *** [serveur] Error 1
有人知道为什么它不工作吗?
boost::filesystem
取决于boost::system
,因此您还必须添加-lboost_system
。
我正在使用cygwin,这个问题的解决方案是链接库
libboost_filesystem-mt
libboost_system-mt
链接器的调用如下所示:
g++ -o "bin.exe" ./src/reader.o ./src/bin.o -llibboost_filesystem-mt -llibboost_system-mt
相关文章:
- 编译 Boost 时在 OS X 上的"ld:未知选项:-soname"
- 用STD = C 11或其他标准编译Boost,例如Ash C 14
- 编译Boost ASIO示例时出现错误
- 使用Cygwin win32_api.hpp编译Boost Log中的错误
- 无法编译 boost::asio::basic_datagram_socket<boost::asio::ip::udp>::basic_datagram_socket()
- 编译boost.spirit.karma示例,customize_embedded_container.cpp失败
- 在 solaris cc v5.8 上编译 Boost
- 在Windows上使用zlib编译boost 1.62 / 1.63
- 错误编译Boost.log
- 试图编译Boost和openSSL时(使用WebSocket 或CPPRESTSDK)进行编译错误
- 在Windows上编译Boost :: ASIO示例
- 我可以编译boost.python模块而没有BJAM
- 在spirit parser Action中,在上下文参数上编译boost :: bind(成员函数)上的错误
- 在 Linux 上编译 boost asio 时出现链接错误
- 在目标平台上编译 Boost 自己是否有意义
- 编译 Boost.Bind时出错
- 在OS X上使用clang编译boost regex时发生链接错误
- 编译boost时"threading=multi"究竟做了什么
- 编译 boost 文件系统的教程文件时遇到问题
- 从Linux到Windows交叉编译boost 1.57的问题