I have installed sudo apt-get install libxml2-dev but I don't know why do I get these error message when I want to make the libaiml AIML interpreter:
make all-recursive
make[1]: Entering directory '/home/m/libaiml'
Making all in src
make[2]: Entering directory '/home/m/libaiml/src'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/home/m/libaiml/src'
Making all in test_app
make[2]: Entering directory '/home/m/libaiml/test_app'
Making all in aiml
make[3]: Entering directory '/home/m/libaiml/test_app/aiml'
make[3]: Nothing to be done for 'all'.
make[3]: Leaving directory '/home/m/libaiml/test_app/aiml'
make[3]: Entering directory '/home/m/libaiml/test_app'
/bin/bash ../libtool --tag=CXX --mode=link g++ -Wall -Werror -ansi -pedantic `xml2-config --cflags` -g -O2 -o test_app `xml2-config --libs` main.o ../src/libaiml.a -lstd_utils
g++ -Wall -Werror -ansi -pedantic -I/usr/include/libxml2 -g -O2 -o test_app main.o -lxml2 ../src/libaiml.a -lstd_utils
../src/libaiml.a(user_manager.o): In function `aiml::cUserManager::cUserManager(aiml::cCore&)':
/home/m/libaiml/src/user_manager.cpp:32: undefined reference to `xmlNewParserCtxt'
../src/libaiml.a(user_manager.o): In function `aiml::cUserManager::~cUserManager()':
/home/m/libaiml/src/user_manager.cpp:36: undefined reference to `xmlFreeParserCtxt'
../src/libaiml.a(user_manager.o): In function `aiml::cUserManager::save(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/m/libaiml/src/user_manager.cpp:101: undefined reference to `xmlNewTextWriterFilename'
/home/m/libaiml/src/user_manager.cpp:104: undefined reference to `xmlTextWriterSetIndent'
/home/m/libaiml/src/user_manager.cpp:105: undefined reference to `xmlTextWriterSetIndentString'
/home/m/libaiml/src/user_manager.cpp:108: undefined reference to `xmlTextWriterStartDocument'
/home/m/libaiml/src/user_manager.cpp:109: undefined reference to `xmlTextWriterStartElement'
/home/m/libaiml/src/user_manager.cpp:113: undefined reference to `xmlTextWriterStartElement'
/home/m/libaiml/src/user_manager.cpp:114: undefined reference to `xmlTextWriterWriteAttribute'
/home/m/libaiml/src/user_manager.cpp:118: undefined reference to `xmlTextWriterStartElement'
/home/m/libaiml/src/user_manager.cpp:119: undefined reference to `xmlTextWriterWriteAttribute'
/home/m/libaiml/src/user_manager.cpp:120: undefined reference to `xmlTextWriterWriteCDATA'
/home/m/libaiml/src/user_manager.cpp:121: undefined reference to `xmlTextWriterEndElement'
/home/m/libaiml/src/user_manager.cpp:123: undefined reference to `xmlTextWriterEndElement'
/home/m/libaiml/src/user_manager.cpp:126: undefined reference to `xmlTextWriterEndElement'
/home/m/libaiml/src/user_manager.cpp:127: undefined reference to `xmlTextWriterEndDocument'
/home/m/libaiml/src/user_manager.cpp:138: undefined reference to `xmlFreeTextWriter'
../src/libaiml.a(user_manager.o): In function `aiml::cUserManager::load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/m/libaiml/src/user_manager.cpp:51: undefined reference to `xmlCtxtReadFile'
/home/m/libaiml/src/user_manager.cpp:55: undefined reference to `xmlDocGetRootElement'
/home/m/libaiml/src/user_manager.cpp:93: undefined reference to `xmlFreeDoc'
../src/libaiml.a(config_parser.o): In function `aiml::cConfigParser::cConfigParser(aiml::cCore&)':
/home/m/libaiml/src/config_parser.cpp:38: undefined reference to `xmlNewParserCtxt'
../src/libaiml.a(config_parser.o): In function `aiml::cConfigParser::~cConfigParser()':
/home/m/libaiml/src/config_parser.cpp:42: undefined reference to `xmlFreeParserCtxt'
../src/libaiml.a(config_parser.o): In function `aiml::cConfigParser::load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)':
/home/m/libaiml/src/config_parser.cpp:51: undefined reference to `xmlCtxtReadFile'
/home/m/libaiml/src/config_parser.cpp:55: undefined reference to `xmlDocGetRootElement'
/home/m/libaiml/src/config_parser.cpp:78: undefined reference to `xmlFreeDoc'
../src/libaiml.a(aiml_parser.o): In function `aiml::AIMLparser::onError()':
/home/m/libaiml/src/aiml_parser.cpp:120: undefined reference to `xmlCtxtGetLastError'
/home/m/libaiml/src/aiml_parser.cpp:120: undefined reference to `xmlCtxtGetLastError'
/home/m/libaiml/src/aiml_parser.cpp:124: undefined reference to `xmlStopParser'
../src/libaiml.a(aiml_parser.o): In function `aiml::AIMLparser::onFatalError()':
/home/m/libaiml/src/aiml_parser.cpp:130: undefined reference to `xmlCtxtGetLastError'
/home/m/libaiml/src/aiml_parser.cpp:130: undefined reference to `xmlCtxtGetLastError'
/home/m/libaiml/src/aiml_parser.cpp:134: undefined reference to `xmlStopParser'
../src/libaiml.a(aiml_parser.o): In function `aiml::AIMLparser::startElement(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::list<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)':
/home/m/libaiml/src/aiml_parser.cpp:211: undefined reference to `xmlStopParser'
/home/m/libaiml/src/aiml_parser.cpp:296: undefined reference to `xmlStopParser'
/home/m/libaiml/src/aiml_parser.cpp:337: undefined reference to `xmlStopParser'
../src/libaiml.a(aiml_parser.o): In function `aiml::AIMLparser::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, bool)':
/home/m/libaiml/src/aiml_parser.cpp:88: undefined reference to `xmlCreateFileParserCtxt'
/home/m/libaiml/src/aiml_parser.cpp:94: undefined reference to `xmlParseDocument'
/home/m/libaiml/src/aiml_parser.cpp:102: undefined reference to `xmlFreeDoc'
/home/m/libaiml/src/aiml_parser.cpp:103: undefined reference to `xmlFreeParserCtxt'
collect2: error: ld returned 1 exit status
Makefile:225: recipe for target 'test_app' failed
make[3]: *** [test_app] Error 1
make[3]: Leaving directory '/home/m/libaiml/test_app'
Makefile:274: recipe for target 'all-recursive' failed
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory '/home/m/libaiml/test_app'
Makefile:250: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/m/libaiml'
Makefile:179: recipe for target 'all' failed
make: *** [all] Error 2
Related
I'm trying to start a new prject and build s2e in a new directory. But at arounf the 100% mark, it gives me an undefined reference error. The relevant part (imo) is this:
[ 92%] Linking CXX executable ../ExprTest
../../lib/libkleeCore.a(Executor.cpp.o): In function `klee::Executor::setModule(llvm::Module*, klee::Interpreter::ModuleOptions const&, bool)':
~/s2e_projects/source/s2e/klee/include/klee/Internal/Module/KModule.h:189: undefined reference to `klee::KModule::KModule(llvm::Module*)'
My directory structure is such:
|-s2e-env
|-s2e_projects
|-venv
I followed the steps from here: http://s2e.systems/docs/s2e-env.html I followed all the steps upto s2e build which is where this problem occurs.
For reference, the (truncated) output which I got from doing s2e build &> log:
[ 88%] Built target kleeModule
make[3]: Entering directory '~/s2e_projects/build/klee-release'
make[3]: Entering directory '~/s2e_projects/build/klee-release'
make[3]: Entering directory '~/s2e_projects/build/klee-release'
make[3]: Leaving directory '~/s2e_projects/build/klee-release'
make[3]: Leaving directory '~/s2e_projects/build/klee-release'
make[3]: Leaving directory '~/s2e_projects/build/klee-release'
make[3]: Entering directory '~/s2e_projects/build/klee-release'
make[3]: Entering directory '~/s2e_projects/build/klee-release'
make[3]: Entering directory '~/s2e_projects/build/klee-release'
[ 91%] Linking CXX executable ../ADTTest
[ 91%] Linking CXX executable ../UtilsTest
[ 92%] Linking CXX executable ../ExprTest
../../lib/libkleeCore.a(Executor.cpp.o): In function `klee::Executor::setModule(llvm::Module*, klee::Interpreter::ModuleOptions const&, bool)':
~/s2e_projects/source/s2e/klee/include/klee/Internal/Module/KModule.h:189: undefined reference to `klee::KModule::KModule(llvm::Module*)'
../../lib/libkleeCore.a(Executor.cpp.o): In function `klee::Executor::setModule(llvm::Module*, klee::Interpreter::ModuleOptions const&, bool)':
~/s2e_projects/build/llvm-10.0.0.src/include/llvm/IR/DataLayout.h:393: undefined reference to `llvm::DataLayout::getPointerSize(unsigned int) const'
../../lib/libkleeCore.a(Executor.cpp.o): In function `klee::Executor::setModule(llvm::Module*, klee::Interpreter::ModuleOptions const&, bool)':
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:107: undefined reference to `klee::KModule::linkLibraries(klee::Interpreter::ModuleOptions const&)'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:108: undefined reference to `klee::KModule::buildShadowStructures()'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:110: undefined reference to `klee::KModule::prepare(klee::Interpreter::ModuleOptions const&, klee::InterpreterHandler*)'
../../lib/libkleeCore.a(Executor.cpp.o): In function `klee::Executor::initializeGlobalObject(klee::ExecutionState&, boost::intrusive_ptr<klee::ObjectState> const&, llvm::Constant const*, unsigned int)':
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:150: undefined reference to `llvm::ConstantDataSequential::getNumElements() const'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:151: undefined reference to `llvm::ConstantDataSequential::getElementAsConstant(unsigned int) const'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:153: undefined reference to `llvm::DataLayout::getStructLayout(llvm::StructType*) const'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:158: undefined reference to `klee::KModule::evalConstant(std::unordered_map<llvm::GlobalValue const*, klee::ref<klee::ConstantExpr>, std::hash<llvm::GlobalValue const*>, std::equal_to<llvm::GlobalValue const*>, std::allocator<std::pair<llvm::GlobalValue const* const, klee::ref<klee::ConstantExpr> > > > const&, llvm::Constant const*, klee::KInstruction const*)'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:163: undefined reference to `klee::ConstantExpr::ZExt(unsigned int)'
../../lib/libkleeCore.a(Executor.cpp.o): In function `klee::Executor::initializeGlobals(klee::ExecutionState&)':
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:200: undefined reference to `llvm::Value::getName() const'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:241: undefined reference to `llvm::Value::getName() const'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:247: undefined reference to `llvm::GlobalValue::isDeclaration() const'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:258: undefined reference to `llvm::Value::getName() const'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:260: undefined reference to `llvm::Value::getName() const'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:262: undefined reference to `llvm::Value::getName() const'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:268: undefined reference to `llvm::Value::getName() const'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:281: undefined reference to `llvm::Value::getName() const'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:306: undefined reference to `klee::KModule::evalConstant(std::unordered_map<llvm::GlobalValue const*, klee::ref<klee::ConstantExpr>, std::hash<llvm::GlobalValue const*>, std::equal_to<llvm::GlobalValue const*>, std::allocator<std::pair<llvm::GlobalValue const* const, klee::ref<klee::ConstantExpr> > > > const&, llvm::Constant const*, klee::KInstruction const*)'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:311: undefined reference to `llvm::Value::getName() const'
../../lib/libkleeCore.a(Executor.cpp.o): In function `klee::Executor::initializeGlobals(klee::ExecutionState&)':
~/s2e_projects/build/llvm-10.0.0.src/include/llvm/IR/GlobalVariable.h:92: undefined reference to `llvm::GlobalValue::isDeclaration() const'
../../lib/libkleeCore.a(Executor.cpp.o): In function `klee::Executor::initializeGlobals(klee::ExecutionState&)':
...
I had the exact same error and solved it with:
sudo apt install gcc-9 g++-9
Also check to make sure clang selects the installed gcc-9 toolchain:
$ PATH_TO_S2E/install/bin/clang++ -v
...
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
...
As for why a compatible gcc toolchain is needed, even though clang is used to compile S2E:
Why clang selects a gcc installation?
I'm trying to build a cpp cmake project and link to my Rust project.
cmake_minimum_required(VERSION 3.0)
set (CMAKE_CXX_STANDARD 17)
project(ZLMediaKit_LIB CXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
set(ENABLE_TESTS OFF FORCE)
option(ENABLE_TESTS OFF)
set(ENABLE_OPENSSL FALSE FORCE)
option(ENABLE_OPENSSL OFF)
add_subdirectory(ZLMediaKit)
add_library(libzlmediakit_cpp_interface STATIC interface.cpp)
target_include_directories(libzlmediakit_cpp_interface PUBLIC
.
${CMAKE_CURRENT_SOURCE_DIR}/ZLMediaKit/src
${CMAKE_CURRENT_SOURCE_DIR}/ZLMediaKit/3rdpart/ZLToolKit/src)
target_link_libraries(libzlmediakit_cpp_interface zlmediakit zltoolkit mpeg mov flv libstdc++)
install(TARGETS libzlmediakit_cpp_interface DESTINATION .)
Here's my build.rs:
extern crate cmake;
use cmake::Config;
fn main()
{
let dst = Config::new("zlmediakit_lib").build();
println!("cargo:rustc-link-search=native={}", dst.display());
println!("cargo:rustc-link-lib=static=libzlmediakit_cpp_interface");
}
But I'm getting undefined reference errors:
ong)':
/usr/include/c++/9/ext/new_allocator.h:128: undefined reference to `operator delete(void*)'
/usr/bin/ld: /home/dev/orwell/liborwell_rust/zlmediakit_rust/target/debug/build/zlmediakit_rust-499cc82f14515635/out/liblibzlmediakit_cpp_interface.a(interface.cpp.o): in function `ZLRTSPClient::~ZLRTSPClient()':
/home/dev/orwell/liborwell_rust/zlmediakit_rust/zlmediakit_lib/ZLRTSPClient.h:14: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/usr/bin/ld: /home/dev/orwell/liborwell_rust/zlmediakit_rust/target/debug/build/zlmediakit_rust-499cc82f14515635/out/liblibzlmediakit_cpp_interface.a(interface.cpp.o): in function `std::default_delete<ZLRTSPClient>::operator()(ZLRTSPClient*) const':
/usr/include/c++/9/bits/unique_ptr.h:81: undefined reference to `operator delete(void*, unsigned long)'
/usr/bin/ld: /home/dev/orwell/liborwell_rust/zlmediakit_rust/target/debug/build/zlmediakit_rust-499cc82f14515635/out/liblibzlmediakit_cpp_interface.a(interface.cpp.o): in function `__static_initialization_and_destruction_0(int, int)':
/usr/include/c++/9/iostream:74: undefined reference to `std::ios_base::Init::Init()'
/usr/bin/ld: /usr/include/c++/9/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
/usr/bin/ld: /home/dev/orwell/liborwell_rust/zlmediakit_rust/target/debug/build/zlmediakit_rust-499cc82f14515635/out/liblibzlmediakit_cpp_interface.a(interface.cpp.o):(.data.rel.local.DW.ref.__gxx_personality_v0[DW.ref.__gxx_personality_v0]+0x0): undefined reference to `__gxx_personality_v0'
collect2: error: ld returned 1 exit status
I've researched and found some answers (Link error "undefined reference to `__gxx_personality_v0'" and g++) that old me to link against libstdc++. As you see, I'm already doing that.
If I try to compile the CMake project alone, it links sucessfully. However then I compile everything from the Rust side, it gives this error.
Complete output of rust compilation
So I'd like to get the SFML from the git tag directly using CMake FetchContent. Most of the tutorial are not using this, so I don't really know what to do, I use imgui-sfml-fetchcontent for the reference.
My CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
include(FetchContent)
project(2DComputerGraphics)
set(CMAKE_CXX_STANDARD 17)
# SFML
set(SFML_VERSION "2.5.1")
FetchContent_Declare(
SFML
GIT_REPOSITORY "https://github.com/SFML/SFML.git"
GIT_TAG "${SFML_VERSION}"
)
FetchContent_GetProperties(SFML)
if(NOT SFML_POPULATED)
FetchContent_Populate(SFML)
add_subdirectory(${SFML_SOURCE_DIR} ${SFML_BINARY_DIR})
#
# message("SFML_SOURCE_DIR: ${SFML_SOURCE_DIR}")
# message("SFML_BINARY_DIR: ${SFML_BINARY_DIR}")
endif()
set(SOURCE
"main.cpp"
)
#
# message("Source: ${SOURCE}")
add_executable(2DComputerGraphicsApp
"${SOURCE}"
)
target_include_directories(2DComputerGraphicsApp PRIVATE
"${SFML_INCLUDE_DIR}"
)
#
# message("SFML_INCLUDE_DIR: ${SFML_INCLUDE_DIR}")
target_link_libraries(2DComputerGraphicsApp
"${SFML_LIBRARIES}"
"${SFML_DEPENDENCIES}"
)
#
# message("SFML_LIBRARIES: ${SFML_LIBRARIES}")
# message("SFML_DEPENDENCIES: ${SFML_DEPENDENCIES}")
target_compile_options(2DComputerGraphicsApp PRIVATE -Wall)
And it gives me this error
/usr/bin/ld: CMakeFiles/2DComputerGraphicsApp.dir/main.cpp.o: in function `main':
main.cpp:(.text+0x82): undefined reference to `sf::String::String(char const*, std::locale const&)'
/usr/bin/ld: main.cpp:(.text+0xa0): undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
/usr/bin/ld: main.cpp:(.text+0xd3): undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
/usr/bin/ld: main.cpp:(.text+0x100): undefined reference to `sf::Texture::Texture()'
/usr/bin/ld: main.cpp:(.text+0x119): undefined reference to `sf::Texture::create(unsigned int, unsigned int)'
/usr/bin/ld: main.cpp:(.text+0x132): undefined reference to `sf::Sprite::Sprite(sf::Texture const&)'
/usr/bin/ld: main.cpp:(.text+0x152): undefined reference to `sf::Window::isOpen() const'
/usr/bin/ld: main.cpp:(.text+0x173): undefined reference to `sf::Window::pollEvent(sf::Event&)'
/usr/bin/ld: main.cpp:(.text+0x190): undefined reference to `sf::Window::close()'
/usr/bin/ld: main.cpp:(.text+0x1da): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
/usr/bin/ld: main.cpp:(.text+0x1f7): undefined reference to `sf::RenderTarget::clear(sf::Color const&)'
/usr/bin/ld: main.cpp:(.text+0x210): undefined reference to `sf::Texture::update(unsigned char const*)'
/usr/bin/ld: main.cpp:(.text+0x229): undefined reference to `sf::RenderStates::Default'
/usr/bin/ld: main.cpp:(.text+0x234): undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'
/usr/bin/ld: main.cpp:(.text+0x243): undefined reference to `sf::Window::display()'
/usr/bin/ld: main.cpp:(.text+0x284): undefined reference to `sf::Texture::~Texture()'
/usr/bin/ld: main.cpp:(.text+0x293): undefined reference to `sf::RenderWindow::~RenderWindow()'
/usr/bin/ld: main.cpp:(.text+0x2fd): undefined reference to `sf::Texture::~Texture()'
/usr/bin/ld: main.cpp:(.text+0x311): undefined reference to `sf::RenderWindow::~RenderWindow()'
/usr/bin/ld: CMakeFiles/2DComputerGraphicsApp.dir/main.cpp.o: in function `sf::Sprite::~Sprite()':
main.cpp:(.text._ZN2sf6SpriteD2Ev[_ZN2sf6SpriteD5Ev]+0xf): undefined reference to `vtable for sf::Sprite'
/usr/bin/ld: main.cpp:(.text._ZN2sf6SpriteD2Ev[_ZN2sf6SpriteD5Ev]+0x1d): undefined reference to `vtable for sf::Sprite'
/usr/bin/ld: main.cpp:(.text._ZN2sf6SpriteD2Ev[_ZN2sf6SpriteD5Ev]+0x35): undefined reference to `sf::Transformable::~Transformable()'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/2DComputerGraphicsApp.dir/build.make:84: 2DComputerGraphicsApp] Error 1
make[3]: Leaving directory '/home/andraantariksa/Projects/2d-computer-graphics/build'
make[2]: *** [CMakeFiles/Makefile2:216: CMakeFiles/2DComputerGraphicsApp.dir/all] Error 2
make[2]: Leaving directory '/home/andraantariksa/Projects/2d-computer-graphics/build'
make[1]: *** [Makefile:130: all] Error 2
make[1]: Leaving directory '/home/andraantariksa/Projects/2d-computer-graphics/build'
make: *** [Makefile:2: build] Error 2
I think it happen because I did not link the SFML correctly. How do I solve this?
The variables are wrong. https://cmake.org/cmake/help/v3.16/module/FetchContent.html states that <name> has to be lower case. Also squareskittles is right, you shouldn't use ${SFML_LIBRARIES} / ${SFML_INCLUDE_DIR}, this is only valid if the old FindSFML.cmake is used.
cmake_minimum_required(VERSION 3.10)
include(FetchContent)
project(2DComputerGraphics)
set(CMAKE_CXX_STANDARD 17)
set(SFML_VERSION "2.5.1")
FetchContent_Declare(
sfml
GIT_REPOSITORY "https://github.com/SFML/SFML.git"
GIT_TAG "${SFML_VERSION}"
)
FetchContent_GetProperties(sfml)
if(NOT sfml_POPULATED)
FetchContent_Populate(sfml)
add_subdirectory(${sfml_SOURCE_DIR} ${sfml_BINARY_DIR})
endif()
set(SOURCE
main.cpp
)
add_executable(2DComputerGraphicsApp
${SOURCE}
)
target_link_libraries(2DComputerGraphicsApp
PRIVATE
sfml-audio
sfml-graphics
sfml-system
sfml-window
)
target_compile_options(2DComputerGraphicsApp PRIVATE -Wall)
I have some troubles with linking the source files (I have added them as Libraries in my CMakeLists) with my main file. Here is my CMakeLists:
cmake_minimum_required(VERSION 2.8.3)
project(ros_bridge)
set(${PROJECT_NAME}_CATKIN_COMPONENTS
nav_msgs
roscpp
sensor_msgs
std_msgs
)
add_compile_options(-std=c++14)
find_package(catkin REQUIRED COMPONENTS ${${PROJECT_NAME}_CATKIN_COMPONENTS})
find_package(RapidJSON REQUIRED)
catkin_package(
INCLUDE_DIRS
include
include/aws_iot_sdk
include/common
include/network
CATKIN_DEPENDS ${${PROJECT_NAME}_CATKIN_COMPONENTS}
)
include_directories(
include
include/aws_iot_sdk
${catkin_INCLUDE_DIRS}
)
## Libraries
add_library(ros_client src/ros_client.cpp)
add_library(ConfigCommon include/common/ConfigCommon.cpp)
add_library(OpenSSL include/network/OpenSSL/OpenSSLConnection.cpp)
add_library(WebSocket include/network/WebSocket/WebSocketConnection.cpp)
add_executable(ros_bridge_node src/main.cpp)
## Lib links
target_link_libraries(ros_client ConfigCommon ${catkin_LIBRARIES} ${RapidJSON_LIBRARIES} OpenSSL WebSocket)
target_link_libraries(ConfigCommon ${catkin_LIBRARIES} ${RapidJSON_LIBRARIES} OpenSSL WebSocket)
target_link_libraries(ros_bridge_node ${catkin_LIBRARIES} ros_client ConfigCommon OpenSSL WebSocket ${RapidJSON_LIBRARIES})
So when the compiler tries to link my main file (which is ros_bridge_node) I get the error with the linkage:
ros_client.cpp:(.text+0x605): undefined reference to `awsiotsdk::util::Logging::GetLogSystem()'
ros_client.cpp:(.text+0x66d): undefined reference to `awsiotsdk::ResponseHelper::ToString[abi:cxx11](awsiotsdk::ResponseCode)'
CMakeFiles/ros_bridge_node.dir/src/ros_client.cpp.o: In function `ros_bridge::RosClient::RunPublish(int&)':
ros_client.cpp:(.text+0x8d9): undefined reference to `awsiotsdk::Utf8String::Create(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/home/abyl/master-wheel/devel/lib/libWebSocket.so: undefined reference to `BIO_push'
/home/abyl/master-wheel/devel/lib/libWebSocket.so: undefined reference to `awsiotsdk::NetworkConnection::Read(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, unsigned long, unsigned long&)'
/home/abyl/master-wheel/devel/lib/libConfigCommon.so: undefined reference to `awsiotsdk::util::JsonParser::InitializeFromJsonFile(rapidjson::GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>, rapidjson::CrtAllocator>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/abyl/master-wheel/devel/lib/libWebSocket.so: undefined reference to `SHA1'
/home/abyl/master-wheel/devel/lib/libWebSocket.so: undefined reference to `BIO_f_base64'
/home/abyl/master-wheel/devel/lib/libWebSocket.so: undefined reference to `awsiotsdk::network::OpenSSLConnection::IsPhysicalLayerConnected()'
/home/abyl/master-wheel/devel/lib/libWebSocket.so: undefined reference to `BIO_set_flags'
/home/abyl/master-wheel/devel/lib/libWebSocket.so: undefined reference to `BIO_new'
So how can I properly link the libraries against my Main file?
EDIT:
I have set the object files of aws_iot_sdk like this:
set(${aws_sdk} /home/ren/aws-iot-device-sdk-cpp/build/CMakeFiles/aws-iot-sdk-cpp.dir/src)
set_source_files_properties(
${aws_sdk_path}
PROPERTIES
EXTERNAL_OBJECT true
GENERATED true
)
And tried to link that against my main file:
target_link_libraries(ros_bridge_node ros_client ConfigCommon Open WebSocket wslay ${RapidJSON_LIBRARIES} ${catkin_LIBRARIES} -lssl ${aws_sdk})
But still getting the same linkage problem. May be I am linking the object files wrong? (Now all the linkage problem is from the aws_iot_sdk)
I installed all the required libraries of CGAL, and added all the library path to my makefile while compiling my program on linux, but it still occured compiling error.
This is the content of my makefile
//--------------------------------------------------
FLAGS = -Wall -g -std=c++11 -O3
BOOST_LIB_PATH = -I /usr/include/include/
CGAL_LIB_PATH = -I /usr/local/include/
all :
g++ $(FLAGS) $(BOOST) $(CGAL) main.cpp -o main
clean :
rm main
//--------------------------------------------------
Bellow is the error message while compiling, Please help !
//----------------------------------------------------
g++ -Wall -g -std=c++11 -O3 -I /usr/include/include/ -I /usr/local/include/ main.cpp -o main
/usr/local/include/CGAL/Interval_nt.h:208: undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
/usr/local/include/CGAL/Interval_nt.h:210: undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
/tmp/cc5WX5dM.o: In function `~Gmpz_rep':
/usr/local/include/CGAL/GMP/Gmpz_type.h:57: undefined reference to `__gmpz_clear'
/usr/local/include/CGAL/GMP/Gmpz_type.h:57: undefined reference to `__gmpz_clear'
/usr/local/include/CGAL/GMP/Gmpz_type.h:57: undefined reference to `__gmpz_clear'
/tmp/cc5WX5dM.o: In function `CGAL::Gmpz::operator==(CGAL::Gmpz const&) const':
/usr/local/include/CGAL/GMP/Gmpz_type.h:154: undefined reference to `__gmpz_cmp'
/usr/local/include/CGAL/GMP/Gmpz_type.h:154: undefined reference to `__gmpz_cmp'
/tmp/cc5WX5dM.o: In function `CGAL::Quadratic_program_solution<CGAL::Gmpz>::optimality_certificate_numerators_begin() const':
/usr/local/include/CGAL/QP_solution.h:460: undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
/tmp/cc5WX5dM.o: In function `CGAL::Gmpz::operator<(CGAL::Gmpz const&) const':
/usr/local/include/CGAL/GMP/Gmpz_type.h:152: undefined reference to `__gmpz_cmp'
/usr/local/include/CGAL/GMP/Gmpz_type.h:152: undefined reference to `__gmpz_cmp'
/usr/local/include/CGAL/GMP/Gmpz_type.h:152: undefined reference to `__gmpz_cmp'
/tmCGAL::assertion_fail(char const*, char const*, int, char const*)'
collect2: error: ld returned 1 exit status
make: *** [all] Error 1
I had a similar problem. I fix it by adding
find_library( GMP_LIB NAMES "gmp" PATHS ${CMAKE_LIBRARY_PATH} )
and add it to the target_link_libraries