How do I compile googleTestLibrary on QNX 6.5.0? - build

I want to compile google Test Library on QNX. But I did not success. I tried everything. Can be seen my compilation errors below
Is someone share to libGoogleTest_g.a and libGoogleTest.a file for me ?
D:/ETCT_PROJECTS/CommonLibrary/Test/ETCCommon/Common/QNXUnitTests/../../../../GoogleTestLibrary/lib\libgoogleTest_g.a(gtest-all.o):
In function `_M_initialize_dispatch<const char* const*>':
/usr/qnx650/target/qnx6/usr/include/c++/4.4.2/ext/new_allocator.h:87: undefined reference to `std::__throw_bad_alloc()'
D:/ETCT_PROJECTS/CommonLibrary/Test/ETCCommon/Common/QNXUnitTests/../../../../GoogleTestLibrary/lib\libgoogleTest_g.a(gtest-all.o):
In function `operator<< <char, std::char_traits<char>, std::allocator<char> >':
/usr/qnx650/target/qnx6/usr/include/c++/4.4.2/bits/basic_string.h:2506:
undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int)'
D:/ETCT_PROJECTS/CommonLibrary/Test/ETCCommon/Common/QNXUnitTests/../../../../GoogleTestLibrary/lib\libgoogleTest_g.a(gtest-all.o):
In function `ValueHolder':
/usr/qnx650/target/qnx6/usr/include/c++/4.4.2/ext/new_allocator.h:87: undefined reference to `std::__throw_bad_alloc()'
D:/ETCT_PROJECTS/CommonLibrary/Test/ETCCommon/Common/QNXUnitTests/../../../../GoogleTestLibrary/lib\libgoogleTest_g.a(gtest-all.o): In function `~DeathTestImpl':
/home/emres/GoogleTest/./src/gtest-death-test.cc:374:
undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
/home/emres/GoogleTest/./src/gtest-death-test.cc:374:
undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
/home/emres/GoogleTest/./src/gtest-death-test.cc:374:
undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'

Check this link to fix the compilation problem.
https://code.google.com/p/googletest/issues/detail?id=444
After you fixed the compilation problem, follow the below steps to create your static library files.
Generate gtest-all.o object file for all configurations(DEBUG RELEASE) simply open QNX momentics and right click to gtest-all.cc
Login to QNX, and copy your gtest-all.o files to any directory
enter the directory to where files copied
create static libraries by using ar(archive) command as shown below.
DEBUG : ar -rv libgoogle_test_g.a gtest-all.o
RELEASE : ar -rv libgoogle_test.a gtest-all.o
Copy *.a files from QNX and use new static library in your project

Related

Running a C++ project with makefile but getting linking errors for source files in subdirectories

I've been trying to get a c++ project to build using this makefile:
https://pastebin.com/vMEMwH4C
The structure of my project is like this:
For context, I'm using a library called Raylib and trying to run on a windows machine. This makefile was provided with a project template and worked just fine before I tried to modify it to run with C++ instead of C and tried to include my source directories for the project instead of including just the main.cpp file.
It compiles just fine, but the linking is where I keep running into issues.
Here's the output when I run the make file:
Executing task in folder VSCode: C:/raylib/w64devkit/bin/mingw32-make.exe RAYLIB_PATH=C:/raylib/raylib PROJECT_NAME=main OBJS=src/main.cpp BUILD_MODE=DEBUG
i686-w64-mingw32-g++ -o main src/main.cpp -Wall -std=c++17 -D_DEFAULT_SOURCE -Wno-missing-braces -g -O0 C:/raylib/raylib/src/raylib.rc.data -Wl,--subsystem,windows -I. -IC:/raylib/raylib/src -IC:/raylib/raylib/src/external -Ilib/ -Ilib/util -Ilib/systems -Ilib/core -Ilib/components -ID://boost_1_81_0 -L. -LC:/raylib/raylib/src -LC:/raylib/raylib/src -lraylib -lopengl32 -lgdi32 -lwinmm -DPLATFORM_DESKTOP
...
C:/raylib/w64devkit/bin/ld.exe: C:\Users\Josh\AppData\Local\Temp\cczAGA5y.o: in function `Z4initv':
D:\Documents\WindowsRaylib\VSCode/src/main.cpp:276: undefined reference to `LocationManager::moveToLocation(nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long long, unsigned long long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, MapLocation&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, MapLocation, 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, MapLocation> > >&, entt::basic_registry<entt::entity, std::allocator<entt::entity> >&, 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> > > > >&)'
... (and a bunch more of messages like these)....
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:408: main] Error 1
I've been looking through many posts trying to figure out how to include the right subdirectories in the linking process, but nothing seems to work. I would really appreciate some help!
(one odd thing I noticed is that the object file mentioned in the error "C:\Users\Josh\AppData\Local\Temp\cczAGA5y.o" is in the AppData folder, not my actual project folder. I can't figure out why, though.)

undefined symbol: std::string when linking static library in VS 2017

I need to link static library to my main project in VS2017. I have included the lib file and compile my main project using Gnu++14. Both of the main project and the static library are in C++. The problem is I don't have information how this static library is built. Then I got these undefined symbol errors related to std::string and std::basic_string when compiling my main project.
Error undefined symbol: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)
Error undefined symbol: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&)
Error undefined symbol: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()
Error undefined symbol: std::string::append(char const*, unsigned long)
Error undefined symbol: std::string::assign(char const*, unsigned long)
Error undefined symbol: std::string::assign(std::string const&)
Error undefined symbol: std::string::_Rep::_M_destroy(std::allocator<char> const&)
Error undefined symbol: std::string::_Rep::_S_empty_rep_storage
I suspect the static library is built differently (maybe clang), but I am not sure. Any lead about the possible cause of this error or possible solution?

Using LTO causes undefined reference to std::basic_string destructor

Decided to try LTO in my build (CentOS 7, CMake 3.14.3, gcc 8.2.1, -std=c++17):
# this adds "-flto -fno-fat-lto-objects"
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
All projects build fine, with exception of one:
/home/user/vcpkg/installed/x64-linux/lib/libazurestorage.a(operation_context.cpp.o): In function `_GLOBAL__sub_I_operation_context.cpp':
operation_context.cpp:(.text.startup+0x9c): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/user/vcpkg/installed/x64-linux/lib/libazurestorage.a(cloud_block_blob.cpp.o): In function `_GLOBAL__sub_I_cloud_block_blob.cpp':
cloud_block_blob.cpp:(.text.startup+0x9c): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/user/vcpkg/installed/x64-linux/lib/libazurestorage.a(cloud_blob_container.cpp.o): In function `_GLOBAL__sub_I_cloud_blob_container.cpp':
cloud_blob_container.cpp:(.text.startup+0x9c): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/user/vcpkg/installed/x64-linux/lib/libazurestorage.a(cloud_blob_shared.cpp.o): In function `_GLOBAL__sub_I_cloud_blob_shared.cpp':
cloud_blob_shared.cpp:(.text.startup+0x9c): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/user/vcpkg/installed/x64-linux/lib/libazurestorage.a(cloud_blob_ostreambuf.cpp.o): In function `_GLOBAL__sub_I_cloud_blob_ostreambuf.cpp':
cloud_blob_ostreambuf.cpp:(.text.startup+0x9c): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/user/vcpkg/installed/x64-linux/lib/libazurestorage.a(cloud_blob_client.cpp.o):cloud_blob_client.cpp:(.text.startup+0x9c): more undefined references to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' follow
collect2: error: ld returned 1 exit status
For some mysterious reason libazurestorage.a provided by vcpkg (where it is built without LTO) can't resolve std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (and only that symbol!).
To make it even more interesting -- other projects that use libazurestorage.a build just fine. I've checked linker's cmdline -- they look practically identical (almost same set of libs, almost same order).
Any ideas what could be wrong? Or how to figure out why other projects build fine?

Understanding make error message

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.

C++ linker errors, Undefined references to Items that should be referenced from a Share Object

I am building a library, called physgameengine, to aid in building games. This game library links against several libraries, including: Ogre3d, Bullet Physics and SDL, which are in the library files libOgreMain-1.6.5.so, libBulletCollision.a, libBulletDynamics.a, libBulletSoftBody.a, libSDL-1.2.so.0. This Library/Shared object appears to build just fine in Ubuntu 9.10, using GCC and Code::blocks. It does build fine on windows with mingw and Code::blocks.
In windows I can make games that compile/link using the library I built just fine, those programs run and do exactly what I expect it to. In Ubuntu when I try to compile/link a game that uses this Library I am making I get lots of undefined reference errors. But none to the functions or objects in the library I built, but rather to the items that my library calls. Here is an example of the errors I get.
> ||warning: libOgreMain-1.6.5.so, needed by ../physgameengine/bin/ubuntudebug/libphysgame.so, not found (try using -rpath or -rpath-link)|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Root::Root(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::StringUtil::BLANK'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btCollisionWorld::updateAabbs()'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Root::createRenderWindow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, unsigned int, bool, std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const*)'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Timer::getMilliseconds()'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Root::createSceneManager(unsigned short, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Root::~Root()'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btCollisionWorld::~btCollisionWorld()'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Root::renderOneFrame()'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btCollisionObject::btCollisionObject()'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Timer::getMillisecondsCPU()'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btSimulationIslandManager::buildAndProcessIslands(btDispatcher*, btCollisionWorld*, btSimulationIslandManager::IslandCallback*)'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Viewport::getActualWidth() const'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Root::initialise(bool, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Camera::lookAt(Ogre::Vector3 const&)'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btCollisionWorld::removeCollisionObject(btCollisionObject*)'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Viewport::getActualHeight() const'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Timer::reset()'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Root::restoreConfig()'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Timer::~Timer()'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::NedAllocImpl::deallocBytes(void*)'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btCollisionWorld::convexSweepTest(btConvexShape const*, btTransform const&, btTransform const&, btCollisionWorld::ConvexResultCallback&, float) const'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::NedAllocImpl::allocBytes(unsigned int, char const*, int, char const*)'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `typeinfo for btCollisionWorld'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btCollisionObject::~btCollisionObject()'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btSimulationIslandManager::btSimulationIslandManager()'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Root::showConfigDialog()'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btCollisionObject::setActivationState(int)'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::LogManager::getSingleton()'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btCollisionWorld::performDiscreteCollisionDetection()'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::LogManager::logMessage(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Ogre::LogMessageLevel, bool)'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Timer::Timer()'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btCollisionWorld::btCollisionWorld(btDispatcher*, btBroadphaseInterface*, btCollisionConfiguration*)'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `typeinfo for btCollisionObject'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Camera::setPosition(Ogre::Vector3 const&)'|
../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btCollisionWorld::addCollisionObject(btCollisionObject*, short, short)'|
||=== Build finished: 36 errors, 1 warnings ===|
The bulk of the code is identical between windows and Linux they seem to have equivalent compile/linker settings. But the Linux game appears to be linking against the original libraries that my library should be linking against. What is going on? Any Ideas on how to fix it?
Unlike in Windows, in Linux systems it's not enough to place a shared library file into the same folder as executable.
You should either provide an LD_LIBRARY_PATH variable or follow the linker's advice and use -rpath (check this question)
The very first line of your error tells you the problem:
libOgreMain-1.6.5.so, needed by libphysgame.so, not found (try using -rpath or -rpath-link)|
You need to specify the directory where libOgreMain is installed. Since you need to use a linker option, you need to use the -Wl feature of gcc. Assuming the files is in /opt/lib, you would add:
gcc -Wl,-rpath-link,/opt/lib ...rest of linker line...
Just based on the first line:
> ||warning: libOgreMain-1.6.5.so, needed by ../physgameengine/bin/ubuntudebug/libphysgame.so, not found (try using -rpath or -rpath-link)|
It looks like your linker is having trouble finding your shared object. Check to make sure your linker's include paths are properly set up.
This is a good link on the subject http://sysprogs.com/w/fixing-rpath-link-issues-with-cross-compilers/
Essentially if you do not have -lmylib for all your libraries you link to, you cannot count on -Lpath to find them. Thus, if /opt/infoa/lib/liba.so depends on /opt/infod/lib/libd.so and you only specify -la, then you need something like this:
gcc -Wl,-rpath-link,/opt/infod/lib -L/opt/infoa/lib -la *.c -o myexec