我想用irrlicht库做一个项目,我想使用cmake(3.11)和Visual Studio(2017)。问题是我突然无法将库与项目链接,而库类却出错。
my.hpp
#ifndef IRRLICHT
#define IRRLICHT
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#else
#include <irr/irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#endif
#endif
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);
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.11)
PROJECT(bomberman CXX)
if (UNIX)
message(STATUS "its is linus system")
endif()
if (WIN32)
message(STATUS "its is win32 system")
INCLUDE_DIRECTORIES(
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/lib
${PROJECT_SOURCE_DIR}/media
${PROJECT_SOURCE_DIR}/src
)
SET(GCC_COVERAGE_COMPILE_INCLUDE " -std=c++11 -I ./include")
add_definitions(${GCC_COVERAGE_COMPILE_INCLUDE})
FILE(GLOB HDRS include/*.hpp)
FILE(GLOB SRCS src/*.cpp)
ADD_EXECUTABLE(bomberman
${HDRS}
${SRCS}
)
TARGET_LINK_LIBRARIES(bomberman PRIVATE lib/Irrlicht)
endif()
if (WIN64)
message(STATUS "its is WIN64 system")
ADD_EXECUTABLE(bomberman main.cpp)
endif()
我有这个错误: 无法定义“ IrrlichtDevice” 不可识别的“设备” ..etc