如何获得Nvidia';s PhysX 3.3在Linux中链接?

如何获得Nvidia';s PhysX 3.3在Linux中链接?,linux,linker,linker-errors,qmake,physx,Linux,Linker,Linker Errors,Qmake,Physx,因此,我试图从Qt Creator中的HelloWorldRender片段编译代码。 我希望能够做的是在调试器中一步一步地遍历代码,然后处理它,这样我就可以理解如何使用它 然而,问题是,当我尝试构建我的项目时,我得到了大量的链接器错误(达到的最大错误数超过1400)。我几乎可以肯定,原因是由于指定的库的顺序 值得一提的要点 对于那些不熟悉QMake的人:请注意,GCC用于编译这个;QMake中指定的链接器顺序与GCC是一对一的 我尝试了各种不同的链接顺序,有些甚至涉及重复列表中的某些库……我能

因此,我试图从Qt Creator中的HelloWorldRender片段编译代码。 我希望能够做的是在调试器中一步一步地遍历代码,然后处理它,这样我就可以理解如何使用它

然而,问题是,当我尝试构建我的项目时,我得到了大量的链接器错误(达到的最大错误数超过1400)。我几乎可以肯定,原因是由于指定的库的顺序

值得一提的要点

  • 对于那些不熟悉QMake的人:请注意,GCC用于编译这个;QMake中指定的链接器顺序与GCC是一对一的

  • 我尝试了各种不同的链接顺序,有些甚至涉及重复列表中的某些库……我能得到的最接近的错误计数大约是150

  • HelloWorldSnippet(
    libRenderSnippetCHECKED.a
    )所需的一个库(它不是SDK的一部分)已编译完毕,没有任何问题,并在要链接的库列表中指定

  • 这个项目的很多信息(要链接的库、定义的库)都是从搜索这个代码片段的Makefile和破译一行又一行自动生成的代码中获取的

  • PhysX的文档非常稀少,尽管它似乎是一个流行的API。我还没有找到任何能真正描述如何在Linux环境中运行它的东西(公平地说,这个版本大约有2个月了)

  • 正在使用的发行版是Ubuntu 13.10。使用Optimus设置在x86_64体系结构上编译

除了我的项目文件之外,为了方便起见,我还包括了未添加的HelloWorld文件

.pro文件


SnippetHelloWorld.cpp


//此代码包含NVIDIA机密信息,并向您披露
//根据单独提供给您的NVIDIA软件许可协议。
//
//通知
//NVIDIA Corporation及其许可人保留所有知识产权和
//对本软件和相关文档的所有权,以及
//任何修改。任何使用、复制、披露或
//本软件和相关文档的分发,无需明示
//严禁与NVIDIA公司签订许可协议。
//
//所有NVIDIA设计规范、代码均按“原样”提供。英伟达制造
//没有关于以下方面的任何明示、暗示、法定或其他保证:
//并明确否认所有非侵权的默示保证,
//适销性,以及特定用途的适用性。
//
//所提供的信息和代码被认为是准确可靠的。
//但是,NVIDIA Corporation对使用此类产品的后果不承担任何责任
//可能侵犯第三方专利或其他权利的信息或信息
//由于它的使用。根据任何专利,不得通过暗示或其他方式授予许可
//或NVIDIA公司的专利权。详情如有更改,恕不另行通知。
//此代码取代并替换以前提供的所有信息。
//NVIDIA Corporation产品未被授权作为关键产品使用
//生命支持设备或系统中的组件,未经
//英伟达公司。
//
//版权所有(c)2008-2013英伟达公司。版权所有。
//版权所有(c)2004-2008 AGEIA Technologies,Inc.保留所有权利。
//版权所有(c)2001-2004 NovodeX AG。版权所有。
#定义PVD_主机“127.0.0.1”
// ****************************************************************************
//这个片段演示了physx的简单用法
//
//它在平面上创建多个长方体堆栈,如果进行渲染,则允许
//用户创建新堆栈并从摄影机位置发射球
// ****************************************************************************
#包括“PxPhysicsAPI.h”
#包括
#如果已定义(PX_PS3)
#包括“PS3Init.h”
#恩迪夫
使用名称空间physx;
PxDefaultAllocator-gAllocator;
PxDefaultErrorCallback-gErrorCallback;
PxFoundation*gFoundation=NULL;
PxPhysics*gpphysics=NULL;
PxDefaultCpuDispatcher*gDispatcher=NULL;
PxScene*gScene=NULL;
PxMaterial*gMaterial=NULL;
PXVisualDebugger连接*
gConnection=NULL;
pxz=10.0f;
PxRigidDynamic*createDynamic(常量PxTransform&t、常量PxGeometry&geometry、常量PxVec3&velocity=PxVec3(0))
{
PxRigidDynamic*dynamic=PxCreateDynamic(*gpphysics,t,geometry,*gmatary,10.0f);
动态->设置角度阻尼(0.5f);
动态->设置线性速度(速度);
gScene->addActor(*动态);
返回动态;
}
void createStack(常量PxTransform&t、PxU32大小、PxReal半范围)
{
PxShape*shape=gpysics->createShape(PxBoxGeometry(半范围、半范围、半范围),*gmatary);
对于(PxU32 i=0;形状(*形状);
PxRigidBodyExt::UpdateMessageAndinertia(*正文,10.0f);
gScene->addActor(*正文);
}
}
形状->释放();
}
void initPhysics(bool交互式)
{
gFoundation=PxCreateFoundation(PX_PHYSICS_版本,gAllocator,Gerror);
PxProfileZoneManager*profileZoneManager=&PxProfileZoneManager::createProfileZoneManager(gFoundation);
gpphysics=PxCreatePhysics(PX_PHYSICS_版本,*gFoundation,PxTolerancesScale(),true,profileZoneManager);
如果(GPPhysics->getPvdConnectionManager())
{
gpphysics->getVisualDebugger()->setVisualizationConstraints(true);
gpphysics->getVisualDebugger()->setVisualDebuggerFlag(PxVisualDebuggerFlag::eTRANSMIT_CONTACTS,true);
gpphysics->getVisualDebugger()->setVisualDebuggerFlag(PxVisualDebuggerFlag::eTRANSMIT_SCENEQUERIES,true);
gConnection=pxVisualDebuggerText::createCon
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp

INCLUDEPATH +=  /opt/PhysX/Include \
                /opt/PhysX/Include/characterkinematic \
                /opt/PhysX/Include/cloth \
                /opt/PhysX/Include/common \
                /opt/PhysX/Include/cooking \
                /opt/PhysX/Include/extensions \
                /opt/PhysX/Include/foundation \
                /opt/PhysX/Include/geometry \
                /opt/PhysX/Include/particles \
                /opt/PhysX/Include/physxprofilesdk \
                /opt/PhysX/Include/physxvisualdebuggersdk \
                /opt/PhysX/Include/pxtask   \
                /opt/PhysX/Include/vehicle  \
                /opt/PhysX/pvd \
                /opt/PhysX/Snippets/SnippetRender

DEFINES +=  PHYSX_PROFILE_SDK \
            RENDER_SNIPPET \
            NDEBUG \
            PX_CHECKED \
            PX_SUPPORT_VISUAL_DEBUGGER


LIBS += -L/opt/PhysX/Lib/linux64

LIBS += -lPvdRuntimeCHECKED \
        -lSimulationControllerCHECKED \
        -lSceneQueryCHECKED \
        -lLowLevelCHECKED \
        -lLowLevelClothCHECKED \
        -lSnippetRenderCHECKED \
        -lPhysX3CHECKED \
        -lPhysX3VehicleCHECKED \
        -lPhysX3CookingCHECKED \
        -lPhysX3ExtensionsCHECKED \
        -lPhysX3CharacterKinematicCHECKED \
        -lPhysXProfileSDKCHECKED \
        -lPhysXVisualDebuggerSDKCHECKED \
        -lPxTaskCHECKED \
        -lPhysX3CommonCHECKED \
        -lGL \
        -lGLU \
        -lglut \
        -lX11 \
        -lrt \
        -lpthread
// This code contains NVIDIA Confidential Information and is disclosed to you
// under a form of NVIDIA software license agreement provided separately to you.
//
// Notice
// NVIDIA Corporation and its licensors retain all intellectual property and
// proprietary rights in and to this software and related documentation and
// any modifications thereto. Any use, reproduction, disclosure, or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA Corporation is strictly prohibited.
//
// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
//
// Information and code furnished is believed to be accurate and reliable.
// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
// information or for any infringement of patents or other rights of third parties that may
// result from its use. No license is granted by implication or otherwise under any patent
// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
// This code supersedes and replaces all information previously supplied.
// NVIDIA Corporation products are not authorized for use as critical
// components in life support devices or systems without express written approval of
// NVIDIA Corporation.
//
// Copyright (c) 2008-2013 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.


#define PVD_HOST "127.0.0.1"

// ****************************************************************************
// This snippet illustrates simple use of physx
//
// It creates a number of box stacks on a plane, and if rendering, allows the
// user to create new stacks and fire a ball from the camera position
// ****************************************************************************

#include "PxPhysicsAPI.h"
#include <ctype.h>

#if defined(PX_PS3)
#include "PS3Init.h"
#endif

using namespace physx;

PxDefaultAllocator      gAllocator;
PxDefaultErrorCallback  gErrorCallback;

PxFoundation*           gFoundation = NULL;
PxPhysics*              gPhysics    = NULL;

PxDefaultCpuDispatcher* gDispatcher = NULL;
PxScene*                gScene      = NULL;

PxMaterial*             gMaterial   = NULL;

PxVisualDebuggerConnection*
                        gConnection = NULL;

PxReal stackZ = 10.0f;

PxRigidDynamic* createDynamic(const PxTransform& t, const PxGeometry& geometry, const PxVec3& velocity=PxVec3(0))
{
    PxRigidDynamic* dynamic = PxCreateDynamic(*gPhysics, t, geometry, *gMaterial, 10.0f);
    dynamic->setAngularDamping(0.5f);
    dynamic->setLinearVelocity(velocity);
    gScene->addActor(*dynamic);
    return dynamic;
}

void createStack(const PxTransform& t, PxU32 size, PxReal halfExtent)
{
    PxShape* shape = gPhysics->createShape(PxBoxGeometry(halfExtent, halfExtent, halfExtent), *gMaterial);
    for(PxU32 i=0; i<size;i++)
    {
        for(PxU32 j=0;j<size-i;j++)
        {
            PxTransform localTm(PxVec3(PxReal(j*2) - PxReal(size-i), PxReal(i*2+1), 0) * halfExtent);
            PxRigidDynamic* body = gPhysics->createRigidDynamic(t.transform(localTm));
            body->attachShape(*shape);
            PxRigidBodyExt::updateMassAndInertia(*body, 10.0f);
            gScene->addActor(*body);
        }
    }
    shape->release();
}

void initPhysics(bool interactive)
{
    gFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, gAllocator, gErrorCallback);
    PxProfileZoneManager* profileZoneManager = &PxProfileZoneManager::createProfileZoneManager(gFoundation);
    gPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *gFoundation, PxTolerancesScale(),true,profileZoneManager);

    if(gPhysics->getPvdConnectionManager())
    {
        gPhysics->getVisualDebugger()->setVisualizeConstraints(true);
        gPhysics->getVisualDebugger()->setVisualDebuggerFlag(PxVisualDebuggerFlag::eTRANSMIT_CONTACTS, true);
        gPhysics->getVisualDebugger()->setVisualDebuggerFlag(PxVisualDebuggerFlag::eTRANSMIT_SCENEQUERIES, true);
        gConnection = PxVisualDebuggerExt::createConnection(gPhysics->getPvdConnectionManager(), PVD_HOST, 5425, 10);
    }

    PxSceneDesc sceneDesc(gPhysics->getTolerancesScale());
    sceneDesc.gravity = PxVec3(0.0f, -9.81f, 0.0f);
    gDispatcher = PxDefaultCpuDispatcherCreate(2);
    sceneDesc.cpuDispatcher = gDispatcher;
    sceneDesc.filterShader  = PxDefaultSimulationFilterShader;
    gScene = gPhysics->createScene(sceneDesc);

    gMaterial = gPhysics->createMaterial(0.5f, 0.5f, 0.6f);

    PxRigidStatic* groundPlane = PxCreatePlane(*gPhysics, PxPlane(0,1,0,0), *gMaterial);
    gScene->addActor(*groundPlane);

    for(PxU32 i=0;i<5;i++)
        createStack(PxTransform(PxVec3(0,0,stackZ-=10.0f)), 10, 2.0f);

    if(!interactive)
        createDynamic(PxTransform(PxVec3(0,40,100)), PxSphereGeometry(10), PxVec3(0,-50,-100));
}

void stepPhysics(bool interactive)
{
    PX_UNUSED(interactive)
    gScene->simulate(1.0f/60.0f);
    gScene->fetchResults(true);
}

void cleanupPhysics(bool interactive)
{
    PX_UNUSED(interactive)
    gScene->release();
    gDispatcher->release();
    PxProfileZoneManager* profileZoneManager = gPhysics->getProfileZoneManager();
    if(gConnection != NULL)
        gConnection->release();
    gPhysics->release();
    profileZoneManager->release();
    gFoundation->release();

    printf("SnippetHelloWorld done.\n");
}

void keyPress(const char key, const PxTransform& camera)
{
    switch(toupper(key))
    {
    case 'B':   createStack(PxTransform(PxVec3(0,0,stackZ-=10.0f)), 10, 2.0f);                      break;
    case ' ':   createDynamic(camera, PxSphereGeometry(3.0f), camera.rotate(PxVec3(0,0,-1))*200);   break;
    }
}

#ifdef PX_XBOXONE
int main(Platform::Array<Platform::String^>^)
#else
int main(int, char**)
#endif
{
#ifdef RENDER_SNIPPET
    extern void renderLoop();
    renderLoop();
#else
    static const PxU32 frameCount = 100;
    initPhysics(false);
    for(PxU32 i=0; i<frameCount; i++)
        stepPhysics(false);
    cleanupPhysics(false);
#endif
}
// This code contains NVIDIA Confidential Information and is disclosed to you
// under a form of NVIDIA software license agreement provided separately to you.
//
// Notice
// NVIDIA Corporation and its licensors retain all intellectual property and
// proprietary rights in and to this software and related documentation and
// any modifications thereto. Any use, reproduction, disclosure, or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA Corporation is strictly prohibited.
//
// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
//
// Information and code furnished is believed to be accurate and reliable.
// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
// information or for any infringement of patents or other rights of third parties that may
// result from its use. No license is granted by implication or otherwise under any patent
// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
// This code supersedes and replaces all information previously supplied.
// NVIDIA Corporation products are not authorized for use as critical
// components in life support devices or systems without express written approval of
// NVIDIA Corporation.
//
// Copyright (c) 2008-2013 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.

#ifdef RENDER_SNIPPET
#include "PxPhysicsAPI.h"

#ifndef _HAS_EXCEPTIONS
#define _HAS_EXCEPTIONS 0
#endif
#include <vector>
#include "SnippetRender.h"
#include "SnippetCamera.h"

using namespace physx;

extern void initPhysics(bool interactive);
extern void stepPhysics(bool interactive);
extern void cleanupPhysics(bool interactive);
extern void keyPress(const char key, const PxTransform& camera);

namespace
{
Snippets::Camera*   sCamera;

void motionCallback(int x, int y)
{
    sCamera->handleMotion(x, y);
}

void keyboardCallback(unsigned char key, int x, int y)
{
    if(key==27)
        exit(0);

    if(!sCamera->handleKey(key, x, y))
        keyPress(key, sCamera->getTransform());
}

void mouseCallback(int button, int state, int x, int y)
{
    sCamera->handleMouse(button, state, x, y);
}

void idleCallback()
{
    glutPostRedisplay();
}

void renderCallback()
{
    stepPhysics(true);

    Snippets::startRender(sCamera->getEye(), sCamera->getDir());

    PxScene* scene;
    PxGetPhysics().getScenes(&scene,1);
    PxU32 nbActors = scene->getNbActors(PxActorTypeSelectionFlag::eRIGID_DYNAMIC | PxActorTypeSelectionFlag::eRIGID_STATIC);
    if(nbActors)
    {
        std::vector<PxRigidActor*> actors(nbActors);
        scene->getActors(PxActorTypeSelectionFlag::eRIGID_DYNAMIC | PxActorTypeSelectionFlag::eRIGID_STATIC, (PxActor**)&actors[0], nbActors);
        Snippets::renderActors(&actors[0], (PxU32)actors.size(), true);
    }

    Snippets::finishRender();
}

void exitCallback(void)
{
    delete sCamera;
    cleanupPhysics(true);
}
}

void renderLoop()
{
    sCamera = new Snippets::Camera(PxVec3(50.0f, 50.0f, 50.0f), PxVec3(-0.6f,-0.2f,-0.7f));

    Snippets::setupDefaultWindow("PhysX Snippet HelloWorld");
    Snippets::setupDefaultRenderState();

    glutIdleFunc(idleCallback);
    glutDisplayFunc(renderCallback);
    glutKeyboardFunc(keyboardCallback);
    glutMouseFunc(mouseCallback);
    glutMotionFunc(motionCallback);
    motionCallback(0,0);

    atexit(exitCallback);

    initPhysics(true);
    glutMainLoop();
}
#endif
LIBS += -Wl,--start-group \
        -lPvdRuntimeCHECKED \
        -lSimulationControllerCHECKED \
        ... \
        -Wl,--end-group