2017-01-22 4 views
1

SimuroSot (로봇 축구 시뮬레이터) 전략 (이 프로그램에서 읽은 dll)을 준비해야합니다. CLion에서 작성할 수 있다면 좋겠지 만 CMake와는 경험이 없습니다.빌드 (DevCpp에서 변환) Cmake를 사용하여 SimuroSot 시뮬레이터 용 Win32 DLL

내가 가지고있는 작업 버전은 DevCpp 프로젝트입니다. 그것을 Cmake로 변환하는 방법?

프로젝트 포함 3 내보내기 기능과 일부 구조체와

  • Strategy.h.

IMO 중요한 옵션

  • Team2.dll
  • libTeam2.a
  • libTeam2.def :
  • 는 Strategy.cpp는 DllMain 함수와

그것은 파일을 빌드 Strategy.dev :

,363,210 내 현재 CMake이다
Compiler=-D__GNUWIN32__ -W -DWIN32 -DNDEBUG -D_WINDOWS -D_MBCS -D_USRDLL [email protected]@_ 
CppCompiler=-D__GNUWIN32__ -W -DWIN32 -DNDEBUG -D_WINDOWS -D_MBCS -D_USRDLL [email protected]@_ 
Linker=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 [email protected]@_ 

, 만 Team2.dll 만들고 내보내는 기능 (표시) 실행되지 않습니다

cmake_minimum_required(VERSION 3.6) 
project(SimuroSotTest) 
set(CMAKE_CXX_STANDARD 98) 

set(SOURCE_FILES 
     library.cpp 
     library.h 
     ) 

add_library(Team2 MODULE ${SOURCE_FILES}) 
set_target_properties(Team2 PROPERTIES PREFIX "") 
target_compile_options(Team2 PRIVATE -D__GNUWIN32__ -W -DWIN32 -DNDEBUG -D_WINDOWS -D_MBCS -D_USRDLL -DSTRATEGY_EXPORTS) 
install(TARGETS Team2 DESTINATION /cygdrive/c/Strategy/yellow/) 


# CLion does not suppot above "install" so I have to execute it 
add_custom_target(
     install_all 
     $(MAKE) install 
     DEPENDS Team2 
     COMMENT "Installing ${PROJECT_NAME}" 
) 

library.h :

#ifndef Strategy_H 
#define Strategy_H 

#include <windows.h> 
#include <string.h> 
#include <stdio.h> 

// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the STRATEGY_EXPORTS 
// symbol defined on the command line. this symbol should not be defined on any project 
// that uses this DLL. This way any other project whose source files include this file see 
// STRATEGY_API functions as being imported from a DLL, wheras this DLL sees symbols 
// defined with this macro as being exported. 
#ifdef STRATEGY_EXPORTS 
#define STRATEGY_API __declspec(dllexport) 
#else 
#define STRATEGY_API __declspec(dllimport) 
#endif 

typedef struct 
{ 
    double x, y, z; 
} Vector3D; 

typedef struct 
{ 
    long left, right, top, bottom; 
} Bounds; 

typedef struct 
{ 
    Vector3D pos; 
    double rotation; 
    double velocityLeft, velocityRight; 
} Robot; 

typedef struct 
{ 
    Vector3D pos; 
    double rotation; 
} OpponentRobot; 

typedef struct 
{ 
    Vector3D pos; 
} Ball; 

typedef struct 
{ 
    Robot home[5]; 
    OpponentRobot opponent[5]; 
    Ball currentBall, lastBall, predictedBall; 
    Bounds fieldBounds, goalBounds; 
    long gameState; 
    long whosBall; 
    void *userData; 
} Environment; 

/* MUST BE IMPLEMENTED */ 
extern "C" STRATEGY_API void Create (Environment *env); 
extern "C" STRATEGY_API void Strategy (Environment *env); 
extern "C" STRATEGY_API void Destroy (Environment *env); 

#endif // Strategy_H 

library.cpp :

#include "library.h" 

BOOL APIENTRY DllMain(HANDLE hModule, 
DWORD ul_reason_for_call, 
     LPVOID lpReserved 
) 
{ 
switch (ul_reason_for_call) 
{ 
case DLL_PROCESS_ATTACH: 
case DLL_THREAD_ATTACH: 
case DLL_THREAD_DETACH: 
case DLL_PROCESS_DETACH: 
break; 
} 
return TRUE; 
} 

extern "C" STRATEGY_API void Create (Environment *env) 
{ 
    // allocate user data and assign to env->userData 
    // eg. env->userData = (void *) new MyVariables(); 
} 

extern "C" STRATEGY_API void Destroy (Environment *env) 
{ 
    // free any user data created in Create (Environment *) 

    // eg. if (env->userData != NULL) delete (MyVariables *) env->userData; 
} 

extern "C" STRATEGY_API void Strategy (Environment *env) 
{ 
    env->home[0].velocityLeft = 100; 
    env->home[0].velocityRight = 100; 

} 

답변

0

문제는 64 비트 dll로 컴파일 된 것입니다.

나도는 MinGW에 Cygwin에서 변경

내 CMakeLists.txt은 다음과 지금 보이는 있도록 : (윈도우 스타일의 경로가 있기 때문에는 MinGW의입니다)

본질은 -m32 옵션입니다

cmake_minimum_required(VERSION 3.6) 
project(SimuroSotTest) 
set(CMAKE_CXX_STANDARD 98) 

set(SOURCE_FILES 
     library.cpp 
     library.h 
     ) 

add_library(Team1 MODULE ${SOURCE_FILES}) 
set_target_properties(Team1 PROPERTIES PREFIX "" COMPILE_FLAGS "-m32" LINK_FLAGS "-m32") 
target_compile_options(Team1 PRIVATE -DSTRATEGY_EXPORTS) 
install(TARGETS Team1 DESTINATION C:/Strategy/blue/) 


add_library(Team2 MODULE ${SOURCE_FILES}) 
set_target_properties(Team2 PROPERTIES PREFIX "" COMPILE_FLAGS "-m32" LINK_FLAGS "-m32") 
target_compile_options(Team2 PRIVATE -DSTRATEGY_EXPORTS) 
install(TARGETS Team2 DESTINATION C:/Strategy/yellow/) 


# CLion does not suppot above "install" so I have to execute it 
add_custom_target(
     install_all 
     $(MAKE) install 
     DEPENDS Team1 Team2 
     COMMENT "Installing ${PROJECT_NAME}" 
)