4

ゲームの構築を支援するために、physgameengine と呼ばれるライブラリを構築しています。このゲーム ライブラリは、ライブラリ ファイル libOgreMain-1.6.5.so、libBulletCollision.a、libBulletDynamics.a、libBulletSoftBody.a、libSDL-1.2.so.0 にある Ogre3d、Bullet Physics、SDL などの複数のライブラリとリンクしています。 . この Library/Shared オブジェクトは、GCC と Code::blocks を使用して、Ubuntu 9.10 で問題なくビルドされているようです。mingw と Code::blocks を使用して Windows で問題なくビルドできます。

ウィンドウでは、ビルドしたライブラリを使用してコンパイル/リンクするゲームを作成できます。これらのプログラムは実行され、期待どおりに動作します。Ubuntu で、このライブラリを使用するゲームをコンパイル/リンクしようとすると、多くの未定義の参照エラーが発生します。しかし、私が構築したライブラリ内の関数やオブジェクトではなく、私のライブラリが呼び出すアイテムに対してです。これは私が得るエラーの例です。

> ||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 ===|

コードの大部分は、Windows と Linux で同じであり、同等のコンパイル/リンカー設定があるようです。しかし、Linux ゲームは、私のライブラリがリンクすべき元のライブラリにリンクしているようです。何が起こっている?それを修正する方法についてのアイデアはありますか?

4

4 に答える 4

3

Windows とは異なり、Linux システムでは、共有ライブラリ ファイルを実行可能ファイルと同じフォルダーに配置するだけでは十分ではありません。

変数を提供するかLD_LIBRARY_PATH、リンカーのアドバイスに従って使用する必要があります(この質問-rpathを確認してください)

于 2010-01-15T06:10:49.403 に答える
3

エラーの最初の行は、問題を示しています。

libOgreMain-1.6.5.so, needed by libphysgame.so, not found (try using -rpath or -rpath-link)|

libOgreMain がインストールされているディレクトリを指定する必要があります。リンカー オプションを使用する必要があるため、gcc の -Wl 機能を使用する必要があります。ファイルが /opt/lib にあると仮定すると、以下を追加します。

gcc -Wl,-rpath-link,/opt/lib ...rest of linker line...
于 2010-01-15T06:00:46.130 に答える
2

最初の行に基づいて:

> ||warning: libOgreMain-1.6.5.so, needed by ../physgameengine/bin/ubuntudebug/libphysgame.so, not found (try using -rpath or -rpath-link)|

リンカーが共有オブジェクトを見つけるのに問題があるようです。リンカーのインクルード パスが正しく設定されていることを確認してください。

于 2010-01-15T05:51:15.197 に答える
1

これは、件名に関する適切なリンクですhttp://sysprogs.com/w/fixing-rpath-link-issues-with-cross-compilers/

基本的に、リンク先のすべてのライブラリに -lmylib がない場合、それらを見つけるために -Lpath を当てにすることはできません。したがって、/opt/infoa/lib/liba.so が /opt/infod/lib/libd.so に依存していて、-la のみを指定する場合は、次のようなものが必要です。

gcc -Wl,-rpath-link,/opt/infod/lib -L/opt/infoa/lib -la *.c -o myexec

于 2015-03-24T21:52:02.053 に答える