我使用irrlicht创建cmakelist时出错

时间:2019-05-11 16:42:24

标签: c++ cmake irrlicht

我为项目图形创建一个cmakelist.txt。我使用库irrlicht。我遇到“ cmake”后遇到了问题,我确实使我出错了

cmakelist.txt


cmake_minimum_required(VERSION 3.11)
PROJECT(toto)

INCLUDE_DIRECTORIES(
  "/usr/include/irrlicht"
  ${PROJECT_SOURCE_DIR}/include
)

SET(GCC_COVERAGE_COMPILE_FLAGS "-lIrrlicht -lGL -lGLU -lXxf86vm-lX11")
#SET(GCC_COVERAGE_COMPILE_FLAGS "-lIrrlicht -lGL -lGLU -lXrandr -lXi -lXxf86vm -lGLEW")
SET(GCC_COVERAGE_COMPILE_INCLUDE "-std=c++11 -I ./include")

find_package(glfw3 3.1 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(X11)

add_definitions(${GCC_COVERAGE_COMPILE_FLAGS})
add_definitions(${GCC_COVERAGE_COMPILE_INCLUDE})

if (OPENGL_FOUND)
   message("opengl found")
   message("include dir: ${OPENGL_INCLUDE_DIR}")
   message("link libraries: ${OPENGL_gl_LIBRARY}")
else (OPENGL_FOUND)
   message("opengl not found")
endif()


FILE(GLOB SRCS src/*.cpp)
FILE(GLOB HDRS include/*.hpp)

ADD_EXECUTABLE(toto
  ${SRCS}
  ${HDRS}
)

TARGET_LINK_LIBRARIES(toto
  "/usr/lib/libIrrlicht.a"
)


include_directories(${OPENGL_INCLUDE_DIR})
target_include_directories(toto PUBLIC ${OPENGL_INCLUDE_DIR})

target_link_libraries(toto ${OPENGL_gl_LIBRARY} glfw)
target_link_libraries(toto ${OPENGL_glu_LIBRARY})

main.cpp

#include "my.hpp"

int main(int ac, char **av)
{
    /* code */
    printf("toto\n");

    IrrlichtDevice *device =
    createDevice( video::EDT_SOFTWARE, dimension2d<u32>(640, 480), 16,
        false, false, false, 0);

    if (!device)
        return 1;
    device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
 IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
    IGUIEnvironment* guienv = device->getGUIEnvironment();
     guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
        rect<s32>(10,10,260,22), true);
IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
    if (!mesh)
    {
        device->drop();
        return 1;
    }
    IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
     if (node)
    {
        node->setMaterialFlag(EMF_LIGHTING, false);
        node->setMD2Animation(scene::EMAT_STAND);
        node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );
    }
        smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
    while(device->run())
    {
                driver->beginScene(true, true, SColor(255,100,101,140));

        smgr->drawAll();
        guienv->drawAll();

        driver->endScene();
    }
       device->drop();
    return (0);
}

my.hpp

#ifndef IRRLICHT
#define IRRLICHT

#include <stdio.h>
#include <iostream>
#include <irr/irrlicht.h>
#include <cstdlib>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif

#endif

我想要一个可执行文件,但是有这个错误

[ 50%] Building CXX object CMakeFiles/toto.dir/src/main.cpp.o
[100%] Linking CXX executable toto
/usr/bin/ld: /usr/lib/libIrrlicht.a(CIrrDeviceLinux.o): référence au symbole non défini « XConvertSelection »
//usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO manquant dans la ligne de commande
collect2: error: ld returned 1 exit status
CMakeFiles/toto.dir/build.make:86 : la recette pour la cible « toto » a échouée
make[2]: *** [toto] Erreur 1
CMakeFiles/Makefile2:67 : la recette pour la cible « CMakeFiles/toto.dir/all » a échouée
make[1]: *** [CMakeFiles/toto.dir/all] Erreur 2
Makefile:83 : la recette pour la cible « all » a échouée
make: *** [all] Erreur 2

1 个答案:

答案 0 :(得分:0)

您的编译器说您缺少符号XConvertSelection。我相信编译器已经为您提供了答案:

/usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO manquant dans la ligne de commande

搜索错误消息very similar question has already been asked。将X11添加到CMakeLists.txt中的库列表中可以解决您的问题:

target_link_libraries(toto ${X11_LIBRARIES})