什么是未定义的参考/未解决的外部符号错误?什么是常见原因以及如何修复/预防它们?
随意编辑/添加您自己的.
c++ c++-faq linker-errors unresolved-external undefined-reference
我试图Boost在我的项目中包含库,并且一直面临着相同的问题.我在使用Codeblocks IDE的Ubuntu 12.10上,尝试手动从站点读取指令来安装库,但是在使用头文件以及使用前构建的库时出现了错误.
然后我通过terminalby安装了库sudo apt-get install libboost-all-dev.在此之后,在我的Codeblocks程序中,我可以包含标题,#include <boost/regex.hpp>但是当我尝试包含Filesystem库(#include "boost/filesystem/operations.hpp" )的标题时,我收到以下错误:
/usr/include/boost/system/error_code.hpp|214|undefined reference to boost::system::generic_category()'|
Run Code Online (Sandbox Code Playgroud)
我不知道如何解决此错误(特别是在Linux上的Codeblocks中).我真的可以在这里使用一些帮助.
编译器:Gcc
程序代码:仅尝试包含上述文件系统operations.hpp文件.
从Codeblocks构建日志:
Build started on: 20-11-2012 at 18:02.53
Build ended on: 20-11-2012 at 18:02.54
-------------- Build: Debug in libopenFrameworks ---------------
Target is up to date.
-------------- Build: Debug in reader1 ---------------
make -s -f Makefile Debug
linking i686 bin/reader1_debug linux
obj/i686Debug/src/testApp.o: In function `__static_initialization_and_destruction_0':
/usr/include/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:216: …Run Code Online (Sandbox Code Playgroud) 链接期间我有以下警告:
/usr/bin/ld: warning: libxxx.so.6, needed by /a/b/c/libyyy.so, not found (try using -rpath or -rpath-link)
Run Code Online (Sandbox Code Playgroud)
设置环境变量LD_LIBRARY_PATH = path_to_libxxx.so.6使警告静音(添加-Lpath_to_libxxx.so.6没有帮助).
我有一个单独的编译服务器,其中生成的二进制文件只是编译.二进制文件在其他服务器上执行,二进制文件可以看到libxxx.so.6(选中ldd executable).
是否还有其他方法可以在编译时摆脱警告(我有几次并且非常烦人)?
如果我没有放置-lboost_system标志,我会理解这个错误信息,但它确实在这里:
g++ -o build/myproject build/main/main.o -L/usr/local/boost/boost_1_52_0/boost/libs -L/usr/lib -Lbuild -L. -lboost_system -lboost_thread -lpthread -lboost_regex -lpq -lmylibrary build/libmylibrary.a(library.o): In function `__static_initialization_and_destruction_0(int, int)': library.cpp:(.text+0x25f): undefined reference to `boost::system::generic_category()' library.cpp:(.text+0x269): undefined reference to `boost::system::generic_category()' library.cpp:(.text+0x273): undefined reference to `boost::system::system_category()'
你知道我应该调查什么来解决这个问题吗?(我使用gcc 4.6.3)
我是一个autotools newb,我很难弄清楚如何轻松地将特定库链接到一个配置的目标.
我有一个源代码包,我想以通常的方式构建:./ configure && make && make install
不幸的是,其中一个cpps缺少对另一个库的引用.手动编译(调整命令行)有效.但我宁愿"修补"编译脚本.编辑链接参考的标准位置在哪里?
undefined reference to `boost::system::get_system_category()
Run Code Online (Sandbox Code Playgroud)
那是我的错误信息btw.
我正在尝试通过使用CMake创建MSVC9.0项目文件来构建具有boost库的应用程序.
我收到以下错误:
错误3致命错误LNK1104:无法打开文件'libboost_system-vc90-mt-gd-1_44.lib'
这是CMake配置
cmake_minimum_required(VERSION 2.8)
PROJECT( TestProject)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
set(BOOST_ROOT "D:/boost_1_44_0")
set(Boost_USE_MULTITHREADED ON)
FIND_PACKAGE( Boost 1.44.0 REQUIRED unit_test_framework system)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${BOOST_ROOT})
LINK_DIRECTORIES(${LINK_DIRECTORIES} "D:/boost_1_44_0/stage/lib")
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
SET(RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
ADD_EXECUTABLE(testapp
main.cpp)
TARGET_LINK_LIBRARIES(testapp
${Boost_SYSTEM_LIBRARY}
)
SET_TARGET_PROPERTIES( testapp PROPERTIES DEBUG_POSTFIX "d" )
Run Code Online (Sandbox Code Playgroud)
我已经使用以下选项为静态和共享(调试和发布)构建了增强功能.
bjam toolset=msvc variant=debug link=shared runtime-link=shared threading=multi --build-type=complete stage
bjam toolset=msvc variant=release link=shared runtime-link=shared threading=multi --build-type=complete stage
bjam toolset=msvc variant=debug link=static runtime-link=static threading=multi --build-type=complete stage
bjam toolset=msvc variant=release link=static runtime-link=static threading=multi --build-type=complete stage
Run Code Online (Sandbox Code Playgroud)
我不确定我在配置中缺少什么.有什么建议?谢谢.
我想使用c ++为mongoDB开发一个相当简单的应用程序,我按照他们的教程:http://www.mongodb.org/pages/viewpage.action? pageId = 133415
并安装驱动程序我遵循这一个: https ://groups.google.com/forum/ ? fromgroups =#! msg/mongodb-user/-mPG7MDJgm8/nZSiN42DJWIJ(Waitman Gobble/5 jun answer)
但是当我尝试编译一个简单的应用程序时,我会得到以下错误:
致命错误:client/dbclient.h:没有这样的文件或目录
我很确定问题是MongoDB c ++驱动程序尚未安装.
我该如何正确安装?