我想用CMake使用Visual Studio 14構建一個c項目,但是我無法覆蓋由CMake設置的導致項目無法構建的編譯器標誌。我在我的CMakeLists.txt文件中使用此方法CMake覆蓋本地編譯器標誌
set(flags /nologo /c /EHsc /GS- /MTd /Od /TC /Zi /Zp2 /D _USING_V110_SDK71_)
set(CMAKE_C_FLAGS ${flags})
set(rc_flags /l0x809)
set(CMAKE_RC_FLAGS ${rc_flags})
set(linker_flags /NOLOGO /SUBSYSTEM:console /MACHINE:I386 /DLL)
set(CMAKE_LINKER_FLAGS ${linker_flags})
任何幫助將不勝感激!
編輯:主要的CMakeLists.txt的完整的例子是在這裏
cmake_minimum_required(VERSION 3.4)
project(cuism C)
set(WINDOWS_SDK_INCLUDES "C:/Program Files\ (x86)/Microsoft\ SDKs/Windows/v7.1A/Include/")
set(WINDOWS_SDK_LIBRARIES "C:/Program Files\ (x86)/Microsoft\ SDKs/Windows/v7.1A/Lib")
set(WSOCK "WSock32.lib")
set(ODBC "odbc32.lib")
set(ODBCCP "odbccp32.lib")
set(includeDir "${CMAKE_SOURCE_DIR}/include/")
set(resourceDir "${CMAKE_SOURCE_DIR}/resources/")
include_directories(
${includeDir}
${resourceDir}
)
set(CMAKE_LIBRARY_PATH ${WINDOWS_SDK_LIBRARIES})
set(CMAKE_INCLUDE_PATH ${WINDOWS_SDK_INCLUDES})
set(flags "/nologo /c /EHsc /GS- /MTd /Od /TC /Zi /Zp2 /D _USING_V110_SDK71_")
set(CMAKE_C_FLAGS ${flags})
set(rc_flags /l0x809)
set(CMAKE_RC_FLAGS ${rc_flags})
set(linker_flags /NOLOGO /SUBSYSTEM:console /DLL)
set(CMAKE_LINKER_FLAGS ${linker_flags})
message(c flags are ${CMAKE_C_FLAGS})
message(rc flags are ${CMAKE_RC_FLAGS})
message(linker flags are ${CMAKE_LINKER_FLAGS})
message(linker EXE flags are ${CMAKE_EXE_LINKER_FLAGS})
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
ADD_SUBDIRECTORY(cuimbct)
ADD_SUBDIRECTORY(cuimb)
ADD_SUBDIRECTORY(cuidll)
每個sudbdirectory具有類似於這個
set(src cuimb.c "${includeDir}port.c" cuimben.c cuimb.rc)
add_library(cuimb SHARED ${src})
target_link_libraries(cuimb ${WSOCK} ${ODBC} ${ODBCCP})
誤差的CMakeLists.txt是連接由於錯誤代碼LNK2019階段期間
那你試試這麼遠嗎?當上述代碼位於'project()'命令後面時,我會說它應該工作。有關更多細節,請參閱[這裏](http://stackoverflow.com/questions/33828855/is-cmake-set-variable-recursive)。 – Florian
試過add_definitions()和add_compile_options()方法 –
只是猜測:你是否試過在'set(flags)/ nologo/c/EHsc/GS-/MTd/Od/TC/Zi/Zp2/D _USING_V110_SDK71 _「)'? – Florian