-2

I create a cmakelist.txt for a project graphique. I use the library irrlicht. I have a probleme after i had "cmake .", i do make i have error

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

I would like to have an executable but have have this error

[ 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
StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458
Hang
  • 1
  • 1
  • 1
    Welcome to Stack Overflow @Hang! Please have a look at the FAQ [how to ask a "good question"](https://stackoverflow.com/help/how-to-ask), especially the part about a [minimal example](https://stackoverflow.com/help/mcve). Also, most users of Stack Overflow speak English - switching your dev environment to English will make it more likely you'll get a response (or you'll be able to find a valid response via search). – Martin Prazak May 11 '19 at 17:24

1 Answers1

0

Your compiler says that you are missing a symbol XConvertSelection. I believe the compiler already gave you an answer:

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

Searching for the error message, a very similar question has already been asked. Adding X11 to your list of libraries in CMakeLists.txt should fix your issue:

target_link_libraries(toto ${X11_LIBRARIES})
Martin Prazak
  • 1,476
  • 12
  • 20