使用CMake(版本3.13.2)在Windows上使用MSVC编译器(版本19.16.27025.1)构建共享的C库。 我收到以下错误:
Erreur MSB3073 La commande "setlocal
cd "\\vmware-host\Shared Folders\Documents\funnel\build\getopt"
if %errorlevel% neq 0 goto :cmEnd
"C:\Program Files\CMake\bin\cmake.exe" -E __create_def "//vmware-
host/Shared
Folders/Documents/funnel/build/getopt/getopt.dir/Debug/exports.def"
"//vmware-host/Shared
Folders/Documents/funnel/build/getopt/getopt.dir/Debug//objects.txt"
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd
:VCEnd" s'est arrêtée avec le code 1.
定义构建选项的CMakeLists.txt
文件的一些摘录:
# CMakeLists.txt in root
add_compile_options(/Wall /c)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
add_subdirectory(getopt)
# CMakeLists.txt in root/getopt
set(src_files getopt.c getopt1.c)
set(hdr_files ansidecl.h getopt.h)
add_library(getopt SHARED "${src_files}" "${hdr_files}")
(在Windows上构建STATIC
库是可以的。在Linux上使用SHARED
构建gcc
库是可以的。)
-编辑(回答vre的评论)-
在调用set_target_properties
之前运行add_library
会产生以下错误。
set_target_properties Can not find target to add properties to: getopt
使用拟议的生成器运行cmake
会产生以下结果(可能是由于cmake -H
返回的列表中提出了编译器,但未在我的系统上安装编译器:安装此版本会有所帮助吗?)。
-- Selecting Windows SDK version to target Windows 10.0.17763.
CMake Error at CMakeLists.txt:6 (project):
Failed to run MSBuild command:
MSBuild.exe
to get the value of VCTargetsPath:
Le fichier spécifié est introuvable
从控制台运行cmake --build [...]
(先前使用Visual Studio 15 2017
生成了构建系统)会产生以下错误。
"\\vmware-host\Shared Folders\Documents\funnel\build\ALL_BUILD.vcxproj" (cible par défaut) (1) ->
"\\vmware-host\Shared Folders\Documents\funnel\build\src\exe.vcxproj" (cible par défaut) (3) ->
"\\vmware-host\Shared Folders\Documents\funnel\build\getopt\getopt.vcxproj" (cible par défaut) (4) ->
(PreLinkEvent cible) ->
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(13
3,5): error MSB3073: La commande "setlocal [\\vmware-host\Shared Folders\Documents\funnel\build\getopt\getopt.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(133,
5): error MSB3073: cd "\\vmware-host\Shared Folders\Documents\funnel\build\getopt" [\\vmware-host\Shared Folders\Docume
nts\funnel\build\getopt\getopt.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(133,
5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [\\vmware-host\Shared Folders\Documents\funnel\build\getopt\getopt
.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(133,
5): error MSB3073: "C:\Program Files\CMake\bin\cmake.exe" -E __create_def "//vmware-host/Shared Folders/Documents/funne
l/build/getopt/getopt.dir/Release/exports.def" "//vmware-host/Shared Folders/Documents/funnel/build/getopt/getopt.dir/R
elease//objects.txt" [\\vmware-host\Shared Folders\Documents\funnel\build\getopt\getopt.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(133,
5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [\\vmware-host\Shared Folders\Documents\funnel\build\getopt\getopt
.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(133,
5): error MSB3073: :cmEnd [\\vmware-host\Shared Folders\Documents\funnel\build\getopt\getopt.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(133,
5): error MSB3073: endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone [\\vmware-host\Shared Folders\Documents\fu
nnel\build\getopt\getopt.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(133,
5): error MSB3073: :cmErrorLevel [\\vmware-host\Shared Folders\Documents\funnel\build\getopt\getopt.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(133,
5): error MSB3073: exit /b %1 [\\vmware-host\Shared Folders\Documents\funnel\build\getopt\getopt.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(133,
5): error MSB3073: :cmDone [\\vmware-host\Shared Folders\Documents\funnel\build\getopt\getopt.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(133,
5): error MSB3073: if %errorlevel% neq 0 goto :VCEnd [\\vmware-host\Shared Folders\Documents\funnel\build\getopt\getopt
.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(133,
5): error MSB3073: :VCEnd" s'est arrêtée avec le code 1. [\\vmware-host\Shared Folders\Documents\funnel\build\getopt\ge
topt.vcxproj]