I generated RTI code using:
/opt/rti_connext_dds-6.0.0/bin/rtiddsgen -d GENERATED_CODE_DIR -language C++11 -replace IDL_DIR
My CMake file:
link_libraries(gsl gslcblas nnz12 occi clntsh dl nddsc nddscpp2 pthread)
add_definitions(-DRTI -DRTI_64BIT -DRTI_LINUX -DRTI_UNIX -D_GLIBCXX_DEBUG)
include_directories(-isystem /opt/rti_connext_dds-6.0.0/include/ndds)
include_directories(-isystem /opt/rti_connext_dds-6.0.0/include/ndds/hpp)
include_directories(-isystem /opt/rti_connext_dds-6.0.0/include/ndds/hpp/rti)
include_directories(-isystem /opt/rti_connext_dds-6.0.0/include/ndds/hpp/dds)
Now when compiling, I am getting following errors:
undefined reference to `rti::domain::register_type_plugin(dds::domain::TDomainParticipant<rti::domain::DomainParticipantImpl>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, PRESTypePlugin* (*)(), void (*)(PRESTypePlugin*))'
undefined reference to `dds::core::PreconditionNotMetError::PreconditionNotMetError(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
Is there anything I am missing ?
The problem was due to ABI. I am using gcc10.2.
I solved the problem by adding definition:
_GLIBCXX_USE_CXX11_ABI 0
The problem was due to the difference in ABIs of RTI libraries and the occi.so.
Solved the problem by using occi_gcc53.so instead of occi.so library.
Related
I'm stuck on this issue and I don't think it should be this difficult. I'm essentially getting a compilation error with several 'undefined reference' warnings which are, I believe, caused by the library not being properly linked to the project.
The library resources along with the required header files are all located in the include folder of my project as well as in the include path. (For reference, I'm working inside of VScode).
Here's part of my makefile
MYSQL_CONCPP_DIR = /home/me/Git/CppProject/include/cpp-connector-mysql
UTILS_DIR = /home/me/Git/CppProject/include/utils/
CPPFLAGS = -DSTATIC_CONCPP -I $(UTILS_DIR)
LDLIBS = $(MYSQL_CONCPP_DIR)/lib64/libmysqlcppconn8-static.a -I $(UTILS_DIR) -lssl -lcrypto -lpthread
CXXFLAGS := -std=c++17 -Wall -Wextra -g
I started moving towards C++ development maybe a week ago and have been programming for maybe half a year. So, if there is something obvious that I am missing I would not mind being embarrassed on Stack Overflow, as long as I learn something.
I've scoured the internet to find a solution and nothing has worked. I successfully did the exact same thing I'm trying to do (connect to localhost via a User class and a Connector class) in both Java and Python in a few hours, but am stuck on C++ with this issue.
Here's the actual error message I get, which is incredibly difficult to decipher:
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: src/Connector.o: in function `check_lib()':
/home/adis/Git/CppProject/include/cpp-connector-mysql/jdbc/cppconn/driver.h:77: undefined reference to `check(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/adis/Git/CppProject/include/cpp-connector-mysql/jdbc/cppconn/driver.h:78: undefined reference to `check(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&)'
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: src/Connector.o: in function `get_driver_instance_by_name':
/home/adis/Git/CppProject/include/cpp-connector-mysql/jdbc/cppconn/driver.h:90: undefined reference to `_get_driver_instance_by_name'
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: src/Connector.o: in function `mysqlx::abi2::r0::string::traits<char>::to_str[abi:cxx11](mysqlx::abi2::r0::string const&)':
/home/adis/Git/CppProject/include/cpp-connector-mysql/mysqlx/devapi/common.h:225: undefined reference to `mysqlx::abi2::r0::string::Impl::to_utf8[abi:cxx11](mysqlx::abi2::r0::string const&)'
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: src/Connector.o: in function `mysqlx::abi2::r0::DbDoc::DbDoc()':
/home/adis/Git/CppProject/include/cpp-connector-mysql/mysqlx/devapi/document.h:107: undefined reference to `vtable for mysqlx::abi2::r0::DbDoc'
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: src/Connector.o: in function `mysqlx::abi2::r0::DbDoc::~DbDoc()':
/home/adis/Git/CppProject/include/cpp-connector-mysql/mysqlx/devapi/document.h:81: undefined reference to `vtable for mysqlx::abi2::r0::DbDoc'
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: src/Connector.o: in function `mysqlx::abi2::r0::Value::print(std::ostream&) const':
/home/adis/Git/CppProject/include/cpp-connector-mysql/mysqlx/devapi/document.h:508: undefined reference to `mysqlx::abi2::r0::common::Value::print(std::ostream&) const'
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: src/Connector.o:(.data.rel.ro._ZTCN6mysqlx4abi22r05ValueE0_NS1_6common5ValueE[_ZTVN6mysqlx4abi22r05ValueE]+0x18): undefined reference to `typeinfo for mysqlx::abi2::r0::common::Value'
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: src/Connector.o:(.data.rel.ro._ZTCN6mysqlx4abi22r05ValueE0_NS1_6common5ValueE[_ZTVN6mysqlx4abi22r05ValueE]+0x20): undefined reference to `mysqlx::abi2::r0::common::Value::print(std::ostream&) const'
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: src/Connector.o:(.data.rel.ro._ZTIN6mysqlx4abi22r05ValueE[_ZTIN6mysqlx4abi22r05ValueE]+0x28): undefined reference to `typeinfo for mysqlx::abi2::r0::common::Value'
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
make: *** [Makefile:76: main] Error 1
I want to connect to mysql 8 using mysql-c++-connector8 (xdevapi) and I use .so file for linking but I get errors
here is my main.cpp file
#include <iostream>
#include <mysqlx/xdevapi.h>
using namespace ::mysqlx;
using std::cout;
using std::cin;
using std::endl;
int main(){
Session sess("localhost",3306,"root","mypass");
Schema db = sess.getSchema("university");
Collection myColl = db.getCollection("student");
DocResult myDocs = myColl.find("name like :param").execute();
cout<<myDocs.fetchOne();
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(1)
set(CMAKE_CXX_STANDARD 17)
include_directories(~/mysql-connector-c++/include)
link_directories(~/mysql-connector-c++/lib64)
set(PROJECT_LINK_LIBS libmysqlcppconn8.so)
add_executable(myExe main.cpp)
target_link_libraries(myExe ${PROJECT_LINK_LIBS})
Errors:
[ 50%] Linking CXX executable myExe
/usr/bin/ld: CMakeFiles/myExe.dir/main.cpp.o: in function `mysqlx::string::string(char const*)':
/home/amir/mysql-connector-c++/include/mysqlx/devapi/common.h:100: undefined reference to `mysqlx::string::Impl::from_utf8(mysqlx::string&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: CMakeFiles/myExe.dir/main.cpp.o: in function `mysqlx::string::string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/amir/mysql-connector-c++/include/mysqlx/devapi/common.h:105: undefined reference to `mysqlx::string::Impl::from_utf8(mysqlx::string&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: CMakeFiles/myExe.dir/main.cpp.o: in function `mysqlx::string::operator std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >() const':
/home/amir/mysql-connector-c++/include/mysqlx/devapi/common.h:115: undefined reference to `mysqlx::string::Impl::to_utf8[abi:cxx11](mysqlx::string const&)'
/usr/bin/ld: CMakeFiles/myExe.dir/main.cpp.o: in function `void mysqlx::internal::Settings_detail<mysqlx::internal::Settings_traits>::set<true, mysqlx::SessionOption, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, mysqlx::SessionOption, unsigned int&, mysqlx::SessionOption, mysqlx::string const&>(mysqlx::SessionOption, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, mysqlx::SessionOption&&, unsigned int&, mysqlx::SessionOption&&, mysqlx::string const&)':
/home/amir/mysql-connector-c++/include/mysqlx/devapi/detail/settings.h:67: undefined reference to `mysqlx::internal::Settings_detail<mysqlx::internal::Settings_traits>::do_set(std::__cxx11::list<std::pair<int, mysqlx::common::Value>, std::allocator<std::pair<int, mysqlx::common::Value> > >&&)'
/usr/bin/ld: CMakeFiles/myExe.dir/main.cpp.o: in function `void mysqlx::internal::Settings_detail<mysqlx::internal::Settings_traits>::set<true, mysqlx::SessionOption, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(mysqlx::SessionOption, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&)':
/home/amir/mysql-connector-c++/include/mysqlx/devapi/detail/settings.h:67: undefined reference to `mysqlx::internal::Settings_detail<mysqlx::internal::Settings_traits>::do_set(std::__cxx11::list<std::pair<int, mysqlx::common::Value>, std::allocator<std::pair<int, mysqlx::common::Value> > >&&)'
/usr/bin/ld: CMakeFiles/myExe.dir/main.cpp.o: in function `void mysqlx::internal::Settings_detail<mysqlx::internal::Settings_traits>::set<true, mysqlx::SessionOption, mysqlx::string const&>(mysqlx::SessionOption, mysqlx::string const&)':
/home/amir/mysql-connector-c++/include/mysqlx/devapi/detail/settings.h:67: undefined reference to `mysqlx::internal::Settings_detail<mysqlx::internal::Settings_traits>::do_set(std::__cxx11::list<std::pair<int, mysqlx::common::Value>, std::allocator<std::pair<int, mysqlx::common::Value> > >&&)'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/myExe.dir/build.make:95: myExe] Error 1
make[2]: *** [CMakeFiles/Makefile2:68: CMakeFiles/myExe.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:80: CMakeFiles/myExe.dir/rule] Error 2
make: *** [Makefile:118: myExe] Error 2
I don't want to use legacy connectors as it is not recommended .
TL;DR; You need to use the old GCC ABI by setting the _GLIBCXX_USE_CXX11_ABI to 0. This can be done with cmake by adding the following to your CMakeLists.txt:
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
The issue comes from the "Linux - Generic" of the MySQL connector which have likely been built without the new CXX11 ABI of GCC (introduced in gcc 5.1).
Since your compiler is recent, the default is to use the new ABI, so when you include <mysqlx/xdevapi.h>, you create declarations such as:
mysqlx::string::Impl::from_utf8(
mysqlx::string&,
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
...that use the new ABI (see the __cxx11 namespace).
But since the connectors have been built with the old ABI, the libmysqlcppconn8.so contains symbols for functions matching this kind of declaration:
mysqlx::string::Impl::from_utf8(
mysqlx::string&,
std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
You can check this by running readelf -Ws libmysqlcppconn8.so, for the "Linux - Generic" version I get (with a grep from_utf8)1:
1428: 00000000000a0a86 193 FUNC GLOBAL DEFAULT 12 _ZN6mysqlx6string4Impl9from_utf8ERS0_RKSs
9437: 00000000000a0a86 193 FUNC GLOBAL DEFAULT 12 _ZN6mysqlx6string4Impl9from_utf8ERS0_RKSs
But for the Ubuntu 18.10 version I get:
725: 00000000000a23e0 183 FUNC GLOBAL DEFAULT 12 _ZN6mysqlx6string4Impl9from_utf8ERS0_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
10141: 00000000000a23e0 183 FUNC GLOBAL DEFAULT 12 _ZN6mysqlx6string4Impl9from_utf8ERS0_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
The easiest fix is to tell your compiler to use the old ABI, so that the symbol will match. This can be done by setting the _GLIBCXX_USE_CXX11_ABI macro to 0 when compiling:
g++ -D_GLIBCXX_USE_CXX11_ABI=0 main.cpp
...or by adding the following to CMakeLists.txt:
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
If you use multiple external libraries, you have to be careful that those also use the old ABI, otherwise you will likely face the opposite issue, i.e., a library built with the new ABI cannot be used directly to build a program with the old ABI.
1 The "Linux - Generic" version contains reference to the CXX11 ABI, so I do not really know what is going on here. It looks like some parts of the library has been compile with the new ABI.
You may need to download the specific version for current OS instead generic-linux version.
for example rhel8 x86_64 platform, the mysql-connector-c++-8.0.23-1.el8.x86_64.rpm and mysql-connector-c++-devel-8.0.23-1.el8.x86_64.rpm should be downloaded. (https://dev.mysql.com/downloads/connector/cpp/)
Then unarchive that into same folder. (note if you have windows system, please unarchive it in linux since there's some soft link in it)
Then just using it without old CXX11ABI (need NOT to define _GLIBCXX_USE_CXX11_ABI=0)
So, I cloned SqAtx's GitHub repository SuperMarioWorld onto my Ubuntu 16.04 (64bit) machine. I would like to run his Super Mario clone in order to understand his project and learn by the way he did this game.
First of all, I could not compile it as he explained it in the README.md. However, I have successfully compiled an own Battleship game the same way (which tells me Cmake, make, SFML, and a C compiler are correctly installed). As an error I got this error message after running cmake .. from the build folder:
CMake Error at CMakeLists.txt:24 (add_executable):
add_executable called with incorrect number of arguments
-- Found SFML 2.4.0 in /usr/include
CMake Error at CMakeLists.txt:32 (target_link_libraries):
Cannot specify link libraries for target "SuperMarioWorld" which is not
built by this project.
-- Configuring incomplete, errors occurred!
I then modified his CMakeList.txt so that it successfully creates a makefile. My CMakeList.txt looks as follows:
#Change this if you need to target a specific CMake version
cmake_minimum_required (VERSION 2.6)
# Enable debug symbols by default
# must be done before project() statement
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build (Debug or Release)" FORCE)
endif()
project (SuperMarioWorld)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -Wall -g")
# I guess you have not released the project yet :p
set (SuperMarioWorld_VERSION_MAJOR 0)
set (SuperMarioWorld_VERSION_MINOR 1)
set (SuperMarioWorld_VERSION_PATCH 0)
include_directories("${PROJECT_BINARY_DIR}")
set(SOURCE_FILES
EventEngine/Listeners/CharacterDiedListener.cpp
EventEngine/Listeners/CharacterPositionUpdateListener.cpp
EventEngine/Listeners/CloseRequestListener.cpp
EventEngine/Listeners/DebugInfoUpdatedListener.cpp
EventEngine/Listeners/ForegroundItemRemovedListener.cpp
EventEngine/Listeners/ForegroundItemUpdatedListener.cpp
EventEngine/Listeners/GotLevelInfoListener.cpp
EventEngine/Listeners/KeyboardListener.cpp
EventEngine/Listeners/LevelStartListener.cpp
EventEngine/Listeners/MarioJumpListener.cpp
EventEngine/Listeners/MarioKickedEnemyListener.cpp
EventEngine/Listeners/NewCharacterReadListener.cpp
EventEngine/Listeners/NewForegroundItemReadListener.cpp
EventEngine/Listeners/NewPipeReadListener.cpp
EventEngine/Listeners/ToggleIgnoreInputListener.cpp
EventEngine/EventEngine.cpp
Game/CollisionHandler.cpp
Game/GameEngine.cpp
Game/LevelImporter.cpp
Graphics/GraphicsEngine.cpp
Graphics/SpriteHandler.cpp
Sound/SoundEngine.cpp
SuperMario/Game.cpp
SuperMario/main.cpp
System/Characters/Enemy.cpp
System/Characters/Goomba.cpp
System/Characters/MovingObject.cpp
System/Characters/Player.cpp
System/Items/Box.cpp
System/Items/Pipe.cpp
System/irrXML/irrXML.cpp
System/Engine.cpp
System/Util.cpp
)
# Define sources and executable
set (EXECUTABLE_NAME "SuperMarioWorld")
add_executable(${EXECUTABLE_NAME} ${SOURCE_FILES})
# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/lib" ${CMAKE_MODULE_PATH})
#Find any version 2.X of SFML
#See the FindSFML.cmake file for additional details and instructions
find_package(SFML 2 REQUIRED system window graphics network audio)
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
endif()
# Install target
install(TARGETS ${EXECUTABLE_NAME} DESTINATION bin)
With this CMakeList.txt I could successfully create a makefile. Running the make I first got two errors which where the same:
/home/lex/Documents/cs/games/SuperMarioWorld/EventEngine/Listeners/NewForegroundItemReadListener.cpp:21:95: error: taking address of temporary [-fpermissive]
m_graphicsEngine->UpdateForegroundItem(&(_event->GetDisplayableObject()->GetInfoForDisplay()));
So I had to fix it in NewPipeReadListener.cpp on line 24 and in NewForegroundItemReadListener.cpp on line 24. I fixed it like this:
InfoForDisplay temp = _event->GetPipe()->GetInfoForDisplay();
m_graphicsEngine->UpdateForegroundItem(&temp);
Now, the makefile gives me an error I cannot fix, since I don't understand a word.. I would like to include the whole error message here, but Stackoverflow doesn't allow me to do so...
But it starts like this.
[ 2%] Linking CXX executable SuperMarioWorld
CMakeFiles/SuperMarioWorld.dir/EventEngine/Listeners/KeyboardListener.cpp.o: In function `KeyboardListener::onEvent(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Event*)':
/home/lex/Documents/cs/games/SuperMarioWorld/EventEngine/Listeners/KeyboardListener.cpp:12: undefined reference to `KeyboardEvent::GetType()'
/home/lex/Documents/cs/games/SuperMarioWorld/EventEngine/Listeners/KeyboardListener.cpp:13: undefined reference to `KeyboardEvent::GetKey()'
/home/lex/Documents/cs/games/SuperMarioWorld/EventEngine/Listeners/KeyboardListener.cpp:14: undefined reference to `KeyboardEvent::GetType()'
/home/lex/Documents/cs/games/SuperMarioWorld/EventEngine/Listeners/KeyboardListener.cpp:15: undefined reference to `KeyboardEvent::GetKey()'
CMakeFiles/SuperMarioWorld.dir/Game/CollisionHandler.cpp.o: In function `CollisionHandler::HandleCollisionsWithMapEdges(MovingObject&)':
/home/lex/Documents/cs/games/SuperMarioWorld/Game/CollisionHandler.cpp:25: undefined reference to `DisplayableObject::GetCoordinates() const'
CMakeFiles/SuperMarioWorld.dir/Game/CollisionHandler.cpp.o: In function `CollisionHandler::DetectCollisionWithObj(MovingObject&, DisplayableObject&)':
I would appreciate if someone could help me understand this error and possibly make the project run on my system.
EDIT:
After fixing the the first error which was including EventEngine/KeyboardEvent.cpp it links up to a 100% and spits out the following error message:
[100%] Linking CXX executable SuperMarioWorld
CMakeFiles/SuperMarioWorld.dir/Game/CollisionHandler.cpp.o: In function `CollisionHandler::HandleCollisionsWithMapEdges(MovingObject&)':
/home/lex/Documents/cs/games/SuperMarioWorld/Game/CollisionHandler.cpp:25: undefined reference to `DisplayableObject::GetCoordinates() const'
CMakeFiles/SuperMarioWorld.dir/Game/CollisionHandler.cpp.o: In function `CollisionHandler::DetectCollisionWithObj(MovingObject&, DisplayableObject&)':
/home/lex/Documents/cs/games/SuperMarioWorld/Game/CollisionHandler.cpp:40: undefined reference to `DisplayableObject::GetCoordinates() const'
/home/lex/Documents/cs/games/SuperMarioWorld/Game/CollisionHandler.cpp:40: undefined reference to `DisplayableObject::GetCoordinates() const'
CMakeFiles/SuperMarioWorld.dir/Game/CollisionHandler.cpp.o: In function `CollisionHandler::ReactToCollisionsWithObj(MovingObject&, DisplayableObject&, CollisionDirection)':
/home/lex/Documents/cs/games/SuperMarioWorld/Game/CollisionHandler.cpp:45: undefined reference to `DisplayableObject::GetCoordinates() const'
CMakeFiles/SuperMarioWorld.dir/Game/CollisionHandler.cpp.o: In function `CollisionHandler::HandleCollisionWithRect(unsigned int, sf::Rect<float>)':
/home/lex/Documents/cs/games/SuperMarioWorld/Game/CollisionHandler.cpp:73: undefined reference to `DisplayableObject::GetCoordinates() const'
CMakeFiles/SuperMarioWorld.dir/Game/CollisionHandler.cpp.o:/home/lex/Documents/cs/games/SuperMarioWorld/Game/CollisionHandler.cpp:138: more undefined references to `DisplayableObject::GetCoordinates() const' follow
CMakeFiles/SuperMarioWorld.dir/Game/GameEngine.cpp.o: In function `GameEngine::UpdateForegroundItem(unsigned int, sf::Rect<float>)':
/home/lex/Documents/cs/games/SuperMarioWorld/Game/GameEngine.cpp:114: undefined reference to `DisplayableObject::SetCoordinates(sf::Rect<float>)'
CMakeFiles/SuperMarioWorld.dir/Game/LevelImporter.cpp.o: In function `LevelImporter::StoreFloor()':
/home/lex/Documents/cs/games/SuperMarioWorld/Game/LevelImporter.cpp:180: undefined reference to `DisplayableObject::DisplayableObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sf::Vector2<float>, State)'
CMakeFiles/SuperMarioWorld.dir/System/Characters/MovingObject.cpp.o: In function `MovingObject::MovingObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sf::Vector2<float>, State)':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Characters/MovingObject.cpp:5: undefined reference to `DisplayableObject::DisplayableObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sf::Vector2<float>, State)'
/home/lex/Documents/cs/games/SuperMarioWorld/System/Characters/MovingObject.cpp:5: undefined reference to `DisplayableObject::~DisplayableObject()'
CMakeFiles/SuperMarioWorld.dir/System/Characters/MovingObject.cpp.o: In function `MovingObject::MovingObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, float, float, State)':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Characters/MovingObject.cpp:10: undefined reference to `DisplayableObject::DisplayableObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, float, float, State)'
/home/lex/Documents/cs/games/SuperMarioWorld/System/Characters/MovingObject.cpp:10: undefined reference to `DisplayableObject::~DisplayableObject()'
CMakeFiles/SuperMarioWorld.dir/System/Characters/MovingObject.cpp.o: In function `MovingObject::~MovingObject()':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Characters/MovingObject.cpp:25: undefined reference to `DisplayableObject::~DisplayableObject()'
CMakeFiles/SuperMarioWorld.dir/System/Characters/MovingObject.cpp.o: In function `MovingObject::GetInfoForDisplay()':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Characters/MovingObject.cpp:32: undefined reference to `DisplayableObject::GetInfoForDisplay()'
CMakeFiles/SuperMarioWorld.dir/System/Characters/MovingObject.cpp.o:(.rodata._ZTI12MovingObject[_ZTI12MovingObject]+0x10): undefined reference to `typeinfo for DisplayableObject'
CMakeFiles/SuperMarioWorld.dir/System/Items/Box.cpp.o: In function `Box::Box(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sf::Vector2<float>, State)':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Box.cpp:3: undefined reference to `DisplayableObject::DisplayableObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sf::Vector2<float>, State)'
CMakeFiles/SuperMarioWorld.dir/System/Items/Box.cpp.o: In function `Box::Box(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, float, float, State)':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Box.cpp:8: undefined reference to `DisplayableObject::DisplayableObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, float, float, State)'
CMakeFiles/SuperMarioWorld.dir/System/Items/Box.cpp.o:(.rodata._ZTV3Box[_ZTV3Box]+0x20): undefined reference to `DisplayableObject::GetInfoForDisplay()'
CMakeFiles/SuperMarioWorld.dir/System/Items/Box.cpp.o: In function `Box::~Box()':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Box.hpp:9: undefined reference to `DisplayableObject::~DisplayableObject()'
CMakeFiles/SuperMarioWorld.dir/System/Items/Box.cpp.o:(.rodata._ZTI3Box[_ZTI3Box]+0x10): undefined reference to `typeinfo for DisplayableObject'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o: In function `Pipe::Pipe(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sf::Vector2<float>, int, PipeType, EventEngine*)':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Pipe.cpp:5: undefined reference to `DisplayableObject::DisplayableObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sf::Vector2<float>, State)'
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Pipe.cpp:5: undefined reference to `DisplayableObject::~DisplayableObject()'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o: In function `Pipe::~Pipe()':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Pipe.cpp:14: undefined reference to `DisplayableObject::~DisplayableObject()'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o: In function `Pipe::SpawnEnemyIfTimeElapsed()':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Pipe.cpp:50: undefined reference to `DisplayableObject::DisplayableObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, float, float, State)'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o: In function `Pipe::MoveEnemyBeingSpawned(float)':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Pipe.cpp:58: undefined reference to `DisplayableObject::Slide(float, float)'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o: In function `Pipe::IsEnemyReadyToLeavePipe()':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Pipe.cpp:92: undefined reference to `DisplayableObject::GetCoordinates() const'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o:(.rodata._ZTV4Pipe[_ZTV4Pipe]+0x20): undefined reference to `DisplayableObject::GetInfoForDisplay()'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o:(.rodata._ZTV4Pipe[_ZTV4Pipe]+0x28): undefined reference to `DisplayableObject::UpdateAfterCollision(CollisionDirection, ObjectClass)'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o:(.rodata._ZTI4Pipe[_ZTI4Pipe]+0x10): undefined reference to `typeinfo for DisplayableObject'
collect2: error: ld returned 1 exit status
CMakeFiles/SuperMarioWorld.dir/build.make:957: recipe for target 'SuperMarioWorld' failed
make[2]: *** [SuperMarioWorld] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/SuperMarioWorld.dir/all' failed
make[1]: *** [CMakeFiles/SuperMarioWorld.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
EDIT2:
Now, I feel stupid, there was another file I forgot to include, it was System/DisplayableObject.cpp.
Thanks, everyone for the help!!!
You did not include all the source files in the build.
For instance, in your error message the linker is complaining that it is missing the definition for the KeyboardEvent::GetType() function.
Searching the repo on github for KeyboardEvent will quickly tell you that this function is defined in EventEngine/KeyboardEvent.cpp, which is not part of your CMake's SOURCE_FILES.
You might be missing other source files as well. Try fixing the linker errors one by one until it compiles.
I am trying to compile a program using cmake, and am seeing the following linker error:
/home/quant/bin/boost_1_61_0/stage/lib/libboost_log_setup.so:
undefined reference to
boost::filesystem::path_traits::convert(wchar_t const*, wchar_t
const*, std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >&, std::codecvt<wchar_t, char, __mbstate_t>
const&)' /home/quant/bin/boost_1_61_0/stage/lib/libboost_log.so:
undefined reference to
boost::filesystem::path_traits::dispatch(boost::filesystem::directory_entry
const&, std::__cxx11::basic_string,
std::allocator >&)'
The linker command that ninja generated looks like this:
g++ -pthread -DBOOST_ALL_DYN_LINK
utility/test/CMakeFiles/utilityTest.dir/loadCSVTests.cpp.o
utility/test/CMakeFiles/utilityTest.dir/main.cpp.o
utility/test/CMakeFiles/utilityTest.dir/randomDeviceTests.cpp.o -o
utility/test/utilityTest -rdynamic
/home/quant/bin/boost_1_61_0/stage/lib/libboost_thread.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_program_options.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_serialization.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_unit_test_framework.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_system.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_log.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_log_setup.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_filesystem.so
utility/lib/libutilityLib.a utility/testLib/libutilityTestLib.a
utility/lib/libutilityLib.a
/home/quant/bin/boost_1_61_0/stage/lib/libboost_thread.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_program_options.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_serialization.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_unit_test_framework.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_system.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_log.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_log_setup.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_filesystem.so
-Wl,-rpath,/home/quant/bin/boost_1_61_0/stage/lib
As you can see, I am linking against boost_filesystem and boost_system, so it's not the same problem as referenced on this SO post (and the many others like it).
I am using boost 1.61, which I compiled with gcc 5.3 (the same compiler as the one I'm compiling my program with).
What am I doing wrong?
I had a similar issue, this could be because of a new ABI which is introduced from gcc 5.1.
https://github.com/openframeworks/openFrameworks/issues/4203
I fixed mine by adding "add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)" to CMakeLists.txt
I am having some trouble in understanding the following error.
I have declaration/definition of a class in ball_popping.h/ball_popping.cpp. The class is a templated class.
I want to compile the above as a library and link them against my main file, game.cpp which uses the member functions of the above class.
My CMakeLists.txt is as below,
set(EXECUTABLE_NAME ball_popping)
set(LIBRARY_NAME ball_popping_lib)
add_library(${LIBRARY_NAME} STATIC ball_popping.cpp ${INCLUDE_FILES})
add_executable(${EXECUTABLE_NAME} game.cpp)
target_link_libraries(${LIBRARY_NAME} ${Precompiled_LIBRARIES})
target_link_libraries(${EXECUTABLE_NAME} ${LIBRARY_NAME})
The library compiles and links successfully. The executable compiles successfully but the linker throws an error
CMakeFiles/ball_popping.dir/game.cpp.o: In function `int proficio_main<3ul>(int, char**, barrett::ProductManager&, barrett::systems::Wam<3ul>&, config)':
game.cpp:(.text._Z13proficio_mainILm3EEiiPPcRN7barrett14ProductManagerERNS2_7systems3WamIXT_EEE6config[int proficio_main<3ul>(int, char**, barrett::ProductManager&, barrett::systems::Wam<3ul>&, config)]+0x553): undefined reference to `ballpopping::BallPopping<3ul>::BallPopping(barrett::math::Matrix<3, 1, barrett::units::CartesianPosition> const&, UserGravComp<3ul>&, bool const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
game.cpp:(.text._Z13proficio_mainILm3EEiiPPcRN7barrett14ProductManagerERNS2_7systems3WamIXT_EEE6config[int proficio_main<3ul>(int, char**, barrett::ProductManager&, barrett::systems::Wam<3ul>&, config)]+0x1176): undefined reference to `ballpopping::BallPopping<3ul>::InEllipsoid(barrett::math::Matrix<3, 1, barrett::units::CartesianPosition> const&) const'
game.cpp:(.text._Z13proficio_mainILm3EEiiPPcRN7barrett14ProductManagerERNS2_7systems3WamIXT_EEE6config[int proficio_main<3ul>(int, char**, barrett::ProductManager&, barrett::systems::Wam<3ul>&, config)]+0x119a): undefined reference to `ballpopping::BallPopping<3ul>::IsDistanced(barrett::math::Matrix<3, 1, barrett::units::CartesianPosition> const&)'
CMakeFiles/ball_popping.dir/game.cpp.o:(.rodata._ZTVN11ballpopping11BallPoppingILm3EEE[vtable for ballpopping::BallPopping<3ul>]+0x28): undefined reference to `ballpopping::BallPopping<3ul>::operate()'
collect2: ld returned 1 exit status
The constructor for BallPopping, InContact() and InEllipsoid() are defined within ball_popping.cpp.
I would like to know if this is a cmake error. I cannot think it of being a coding error since my library compiles and links successfully.
Thanks to #user4581301 for his input. Including the template definitions from another file at the end of the header did solve the problem.