I'm getting some "undefined reference" errors in ld and am at a loss as to what's causing them.
My makefile builds several executables using commands like this:
g++ -ogui_program1 -Lpath/to/MyLibs gui_program1.o -lMyUI -lMyBusinessLogic \
-lMyUtil -lboost_regex
g++ -ogui_program2 -Lpath/to/MyLibs gui_program2.o -lMyUI -lMyBusinessLogic \
-lMyUtil -lboost_regex
g++ -ocli_program1 -Lpath/to/MyLibs cli_program1.o -lMyUI -lMyBusinessLogic \
-lMyUtil -lboost_regex
g++ -ocli_program2 -Lpath/to/MyLibs cli_program2.o -lMyUI -lMyBusinessLogic \
-lMyUtil -lboost_regex
And so on. (Actually, there are quite a few more libraries than this, but this is the general idea.)
MyUI, MyBusinessLogic, and MyUtil are all dynamic libraries that I've already built. To make writing the makefile simpler, the same list of libraries is used for both GUI and command line programs, even though the command line programs don't need libMyUI.so.
One and only one of the command line programs is giving numerous errors about undefined references to Boost.Regex symbols when I try to link it, even though I'm linking -lboost_regex with every binary:
libMyBusinessLogic.so: undefined reference to `boost::re_detail::perl_matcher >, boost::regex_traits > >::construct_init(boost::basic_regex > > const&, boost::regex_constants::_match_flags)'
libMyBusinessLogic.so: undefined reference to `boost::cpp_regex_traits::toi(char const*&, char const*, int) const'
libMyBusinessLogic.so: undefined reference to `boost::re_detail::perl_matcher, std::allocator > >, std::allocator, std::allocator > > > >, boost::regex_traits > >::match()'
libMyBusinessLogic.so: undefined reference to `boost::re_detail::perl_matcher, std::allocator > >, std::allocator, std::allocator > > > >, boost::regex_traits > >::construct_init(boost::basic_regex > > const&, boost::regex_constants::_match_flags)'
libMyBusinessLogic.so: undefined reference to `boost::re_detail::perl_matcher, std::allocator > >, std::allocator, std::allocator > > > >, boost::regex_traits > >::find()'
libMyBusinessLogic.so: undefined reference to `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)'
libMyBusinessLogic.so: undefined reference to `boost::re_detail::perl_matcher >, boost::regex_traits > >::match()'
Linking all other programs works fine. If I remove -lMyUI from the one command-line program, then it works fine, even though MyUI doesn't show up anywhere in the error list.
Why isn't ld finding Boost.Regex symbols, when I've added -lboost_regex to the end of the command? Why does removing a seemingly unrelated library fix it? Why do other programs link without any problems?
I've figured out at least most of the answer. Due to some sloppiness in my makefile rules, libMyUI.so was linked against boost_regex, but libMyBusinessLogic.so wasn't. I'm guessing that, as a result, linking MyUI caused boost_regex to get pulled in prematurely, before the linker knew all of the symbols that MyBusinessLogic would need from it.
As long as I'm consistent - either all of My*.so link with boost_regex, or none of them do - everything works. I'm not sure which of these solutions is most preferred, but at least I have a fix.
Related
I've a large project which was originally built on Macos, that I'm trying to get compiling on Windows. The makefile for the project is as follows:
CC=C:/cygwin64/bin/g++.exe
BASE_FLAGS = -std=c++14
LDFLAGS = -I/usr/local/Cellar/boost/1.69.0/include -I/opt/local/include -I include/
LLIBFLAGS = -L/usr/local/Cellar/boost/1.68.0/lib
LINKFLAGS = -lboost_thread -lboost_system -l boost_filesystem -l boost_regex -ll -lm
FLAGS = $(BASE_FLAGS) $(LLIBFLAGS) $(LDFLAGS) $(LINKFLAGS)
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
SRCS := $(call rwildcard,src/,*.cpp) $(call rwildcard,src/,*.c)
mac:
cd src; bison -d parse.y --debug -t; flex lex.l
time ./runscripts.sh
$(CC) $(FLAGS) -o main.out $(SRCS)
BASE_FLAGS_WIN = -std=gnu++11
LDFLAGS_WIN = -I include/ -I C:\Users\elllz\Downloads\boost_1_69_0
LLIBFLAGS_WIN = -LC:\Users\elllz\Downloads\boost_1_69_0\stage\lib
LINKFLAGS_WIN = -lm -lboost_system -lboost_regex -lboost_filesystem -lboost_thread
FLAGS_WIN = $(BASE_FLAGS_WIN) $(LDFLAGS_WIN) $(LLIBFLAGS_WIN) $(LINKFLAGS_WIN)
win:
bison -d .\src\parse.y -t -g
flex .\src\lex.l
.\scripts\ALL_HEADER_TOKENS.bat
cp .\parse.tab.h .\src\parse.tab.h
cp .\parse.tab.c .\src\parse.tab.c
cp .\lex.yy.c .\src\lex.yy.c
rm .\parse.tab.h .\parse.tab.c .\lex.yy.c
$(CC) $(FLAGS_WIN) $(SRCS)
Note that the first second is the (working) macos target, and the later is the Windows target. When trying to link boost on Windows, I keep getting a plethora of undefined reference errors, like such:
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE[_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE]+0x15): undefined reference to `boost::filesystem::path::codecvt()'
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE[_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE]+0x15): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::path::codecvt()'
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE[_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE]+0x32): undefined reference to `boost::filesystem::path_traits::convert(char const*, char const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&, std::codecvt<wchar_t, char, _mbstate_t> const&)'
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE[_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE]+0x32): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::path_traits::convert(char const*, char const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&, std::codecvt<wchar_t, char, _mbstate_t> const&)'
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem6existsERKNS0_4pathE[_ZN5boost10filesystem6existsERKNS0_4pathE]+0x1e): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem6existsERKNS0_4pathE[_ZN5boost10filesystem6existsERKNS0_4pathE]+0x1e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem15is_regular_fileERKNS0_4pathE[_ZN5boost10filesystem15is_regular_fileERKNS0_4pathE]+0x1e): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem15is_regular_fileERKNS0_4pathE[_ZN5boost10filesystem15is_regular_fileERKNS0_4pathE]+0x1e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
/cygdrive/c/Users/elllz/AppData/Local/Temp/ccbzCEFH.o:Token.cpp:(.text$_ZN5boost11regex_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS5_EEEcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEEEbT_SD_RNS_13match_resultsISD_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsE[_ZN5boost11regex_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS5_EEEcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEEEbT_SD_RNS_13match_resultsISD_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsE]+0x7e): undefined reference to `boost::re_detail_106900::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::c_regex_traits<char> > >::match()'
/cygdrive/c/Users/elllz/AppData/Local/Temp/ccbzCEFH.o:Token.cpp:(.text$_ZN5boost11regex_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS5_EEEcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEEEbT_SD_RNS_13match_resultsISD_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsE[_ZN5boost11regex_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS5_EEEcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEEEbT_SD_RNS_13match_resultsISD_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsE]+0x7e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::re_detail_106900::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::c_regex_traits<char>
> >::match()'
/cygdrive/c/Users/elllz/AppData/Local/Temp/ccbzCEFH.o:Token.cpp:(.text$_ZN5boost11basic_regexIcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEE6assignEPKcS7_j[_ZN5boost11basic_regexIcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEE6assignEPKcS7_j]+0x31): undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::c_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
/cygdrive/c/Users/elllz/AppData/Local/Temp/ccbzCEFH.o:Token.cpp:(.text$_ZN5boost11basic_regexIcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEE6assignEPKcS7_j[_ZN5boost11basic_regexIcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEE6assignEPKcS7_j]+0x31): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::basic_regex<char, boost::regex_traits<char, boost::c_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
That's only a snippet, all the information I can find says it's a boost linking problem, but I can't pin it down for the life of me. I'm compiling boost 1.69.0 with the commands:
.\boostrap.bat
./bjam
./bjam install
In a similar manner to the instructions found here. I've tried jsut about everything I can think of, as well as spent a lot of time recompiling boost, so any help you might be able to offer would be greatly appreciated!
Things I have tried:
Checking the libaries do exist in /stage/lib, they do, as .a and .dll.a files.
Moving the entire boost folder into a relative path of my build folder, in case I was specifying the link / include folders wrong.
Recompiling boost with a host of options, I can't come close to recalling them all.
I suspect that you may have multiple issues...
Your makefile specifies different versions of the boost libraries: 1.69.0 and 1.68.0
LDFLAGS = -I/usr/local/Cellar/boost/1.69.0/include -I/opt/local/include -I include/
LLIBFLAGS = -L/usr/local/Cellar/boost/1.68.0/lib
It could be as simple as that.
However, on a Windows machine, the command:
.\boostrap.bat
normally assumes building the boost libraries using Visual Studio.
So depending upon where you built the boost libraries from, you may have built Visual Studio lib files, not g++ lib files. You can tell from the library file names:
// gcc, actually mingw73: mgw73
libboost_filesystem-mgw73-mt-x64-1_69.dll.a
// msvc 2017: vc141
boost_filesystem-vc141-mt-x64-1_69.lib
It sounds like yours are correct, but you can specify the g++ compiler explicitly when building boost, e.g.:
.\boostrap.bat gcc
Finally, it's difficult to maintain cross platform makefiles, especially with boost.
I recommend using cmake instead.
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 trying to compile some source codes. However it is throwing some error related to boost library. Here is the error
undefined reference to `boost::re_detail::get_mem_block()'
main.cpp:(.text+0x40a6): undefined reference to `boost::re_detail::verify_options(unsigned int, boost::regex_constants::_match_flags)'
main.cpp:(.text+0x40db): undefined reference to `boost::re_detail::put_mem_block(void*)'
main.cpp:(.text+0x430a): undefined reference to `boost::re_detail::put_mem_block(void*)'
main.o: In function `_ZN7Command12createVectorIdEEvRKSsRSt6vectorIT_SaIS4_EES4_.constprop.1207':
main.cpp:(.text+0x436e): undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
main.cpp:(.text+0x439f): undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
main.cpp:(.text+0x43d0): undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<
I have the boost regex library installed in my system and I have given the path to the library using -L option and specified the library using -lboost_regex option as well. What could be the issue?
It does find the library. But still throwing an error
I met the same problem, and it has been solved. So maybe you had installed an older version of boost before, and the linker linkes the older version.
Try to remove all installed boost library, and reinstall the boost library, your problem will be solved.
I tried to use Boost library but I failed, see my code:
#include "listy.h"
#include <boost/regex.hpp>
using namespace boost;
ListyCheck::ListyCheck() {
}
ListyCheck::~ListyCheck() {
}
bool ListyCheck::isValidItem(std::string &__item) {
regex e("(\\d{4}[- ]){3}\\d{4}");
return regex_match(__item, e);
}
When I tried to compile it I get those messages:
/usr/include/boost/regex/v4/regex_match.hpp:50:
undefined reference to
`boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator,
std::allocator > >,
std::allocator,
std::allocator > > > >,
boost::regex_traits >
::match()'
/usr/include/boost/regex/v4/basic_regex.hpp:425:
undefined reference to
`boost::basic_regex >
::do_assign(char const*, char const*, unsigned int)'
/usr/include/boost/regex/v4/perl_matcher.hpp:366:
undefined reference to
`boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator,
std::allocator > >,
std::allocator,
std::allocator > > > >,
boost::regex_traits >
::construct_init(boost::basic_regex > >
const&,
boost::regex_constants::_match_flags)'
etc...
You need to link to libboost_regex. Add -lboost_regex to the compiler switch if you're using gcc.
Those are linker errors. The Boost regex library is not a header-only library like shared_ptr (for example) - you need to link against the .a or .lib or whatever binary library.
You have to link against boost_regex.
had similar issue.
the solution was to link via cmake with the command target link library:
target_link_libraries(boostGraph Boost::regex Boost::date_time Boost::system Boost::filesystem Boost::thread Boost::graph Boost::program_options)
using the syntax -lboost_regex as offered here did not work (at least not with cmake)
the root issue could have been different versions of libraries, which cause the issue and even though the compiler and the linker do find the regex lib.
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