繁体   English   中英

我尝试编译时使用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 \033[33m[Message]\033[39m Compilation under Linux done\n\n"

.cpp.o  :
        @$(CC) $(CFLAGS) -I$(INCL) -L$(LIB) $(NLIB) -c $< -o $@
        @printf " \033[34m[Compilation]\033[39m %s\n" $<

re      :       fclean all

all     :       $(NAME)

clean   :
        @$(RM) *~ $(OBJS)
        @printf " \033[31m[Delete] \033[39m%s\n" $(OBJS)

fclean  :       clean
        @$(RM) $(NAME)
        @printf "\n \033[31m[Delete] \033[39m%s\n\n" $(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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM