g ++未定义的库符号引用

时间:2017-03-24 03:02:48

标签: c++ linker linker-errors undefined-reference

SFML定义的符号有链接器错误,但我无法看到它们如何发生,尽管我链接了lib。 我正在使用make,我目前正在学习它,我想用它构建一个简约的开发环境。

如果您需要的信息不仅仅是以下内容,请提供更好的信息。我想尽量减少问题的大小。

XXX@XXX ~/Documents/dev/cpp/proj/beep $ make clean                                                                                                         
rm -f build/*.o build/release/*.o build/debug/*.o build/test/*.o
XXX@XXX ~/Documents/dev/cpp/proj/beep $ make tests
//test obj first
g++ -std=c++14 -Wall -pthread -Iinclude   -c test/Packager.ut.cpp -o   build/test/Packager.ut.o -g3
//now the src obj 
g++ -std=c++14 -Wall -pthread -Iinclude   -c src/ClientAddress.cpp -o build/debug/ClientAddress.o -g3
g++ -std=c++14 -Wall -pthread -Iinclude   -c src/Packager.cpp -o build/debug/Packager.o -g3  
g++ -std=c++14 -Wall -pthread -Iinclude   -c src/Package.cpp -o build/debug/Package.o -g3
Built debug object files.
//now the first test itself
g++ -std=c++14 -Wall -pthread -Iinclude  -lsfml-network  build/test/Packager.ut.o build/debug/ClientAddress.o build/debug/Packager.o build/debug/Package.o -g3  -o bin/test/Packager.ut 
build/test/Packager.ut.o: In function `main':
/home/XXX/Documents/dev/cpp/proj/beep/test/Packager.ut.cpp:69: undefined reference to `sf::IpAddress::IpAddress(char const*)'
build/debug/ClientAddress.o: In function `nw::udp::ClientAddress::ClientAddress()':
/home/XXX/Documents/dev/cpp/proj/beep/src/ClientAddress.cpp:21: undefined reference to `sf::IpAddress::IpAddress(char const*)'
build/debug/ClientAddress.o: In function `nw::udp::operator==(nw::udp::ClientAddress const&, nw::udp::ClientAddress const&)':
/home/XXX/Documents/dev/cpp/proj/beep/src/ClientAddress.cpp:33: undefined reference to `sf::operator==(sf::IpAddress const&, sf::IpAddress const&)'
...

依此类推......引用文件内部的所有sf ::引用

如果我尝试编译其他测试(例如ClientAddress),我会得到相同的错误模式

当然我现在想知道我的错误是怎么回事。如您所见,lib与-lsfml-network链接。我还检查了SMFL安装,因此至少不太可能从标准目录中删除lib文件。

我猜我使用g ++,编译和链接订单或smth时出错。

我的项目树:

>bin
----mainexec
--->test
    ----.ut
>build
--->debug
    ----.o
--->release
    ----.o
--->test
    ----.ut.o
>src
---- .cpp
>include
---- .h
>test
---- .ut.cpp

作为问题的第二部分,我想问一下是否有更好的方法来构建测试,因为我只是将每个src-obj与我的test-obj链接,即使有更多的src -obj链接比实际需要。它应该工作,我不必一直维护我的测试依赖项,以后会非常麻烦。什么是常见的?

1 个答案:

答案 0 :(得分:1)

sfml-network依赖sfml-system。尝试在makefile中的链接器命令中-lsfml-system之前添加-lsfml-network