2017-01-22 8 views
1

SimuroSot(ロボットのサッカーシミュレータ)戦略(このプログラムによって読み込まれるDLL)を準備する必要があります。 私がCLionで書くことができれば素晴らしいだろうが、CMakeの経験はない。Cmakeを使用してSimuroSotシミュレータ用のWin32 DLLをビルドする方法(DevCppから変換する)

私が持っている作業版はDevCppプロジェクトです。それをCmakeに変換するには?

プロジェクトが含まれています:3つのエクスポート機能といくつかの構造体と

  • Strategy.h。
  • DllMain関数

とStrategy.cppこれは、ファイルを作成します:から

  • Team2.dll
  • libTeam2.a
  • libTeam2.def

IMOの重要なオプションStrategy.dev:

私の現在の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としてコンパイルしたことです。私のCMakeLists.txtは、次のように今見えるよう

は、私はまた、MinGWのにCygwinを変更:

本質は、-m32オプション(WindowsスタイルのパスがあるためMinGWのである)

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}" 
) 
です
関連する問題