我需要使用在cygwin下运行的visual studio 2013在Windows上编译arithchk.c(来自gdtoa库)。 VS2008一切正常,但当我尝试切换到VS2013时遇到了这个问题:
ladanyi@WIN64-01$ echo $LIB ;c:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/LIB/amd64;c:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/ATLMFC/LIB/amd64;c:/Program Files (x86)/Windows Kits/8.1/lib/winv6.3/um/x64; ladanyi@WIN64-01$ echo $INCLUDE ;c:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/INCLUDE;c:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/ATLMFC/INCLUDE;c:/Program Files (x86)/Windows Kits/8.1/include/shared;c:/Program Files (x86)/Windows Kits/8.1/include/um;c:/Program Files (x86)/Windows Kits/8.1/include/winrt; ladanyi@WIN64-01$ echo $PATH :/cygdrive/c/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE:/cygdrive/c/Program Files (x86)/Microsoft Visual Studio 12.0/VC/BIN:/cygdrive/c/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/Tools:/cygdrive/c/Program Files (x86)/Microsoft Visual Studio 12.0/VC/VCPackages:/cygdrive/c/Program Files (x86)/Windows Kits/8.1/bin/x64:/cygdrive/c/Program Files (x86)/Windows Kits/8.1/bin/x86:/usr/local/bin:/usr/bin:/bin:/usr/bin:/cygdrive/c/Program Files (x86)/Intel/Composer XE 2011 SP1/redist/intel64/ipp:/cygdrive/c/Program Files (x86)/Intel/Composer XE 2011 SP1/redist/intel64/mkl:/cygdrive/c/Program Files (x86)/Common Files/Intel/Shared Libraries/redist/intel64/compiler:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem:/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0:/cygdrive/c/Program Files/Microsoft SQL Server/110/Tools/Binn:/cygdrive/c/Program Files (x86)/Microsoft SDKs/TypeScript/1.0:/cygdrive/c/Program Files (x86)/Windows Kits/10/Windows Performance Toolkit:/cygdrive/c/Program Files/MATLAB/R2015b/bin ladanyi@WIN64-01$ LIB="$LIB" INCLUDE="$INCLUDE" cl -DNO_FPINIT arithchk.c -DNO_LONG_LONG -DNO_SSIZE_T /INCREMENTAL:NO /VERBOSE Microsoft (R) C/C++ Optimizing Compiler Version 18.00.40629 for x86 Copyright (C) Microsoft Corporation. All rights reserved. cl : Command line warning D9035 : option 'V' has been deprecated and will be removed in a future release arithchk.c Microsoft (R) Incremental Linker Version 12.00.40629.0 Copyright (C) Microsoft Corporation. All rights reserved. /out:arithchk.exe arithchk.obj arithchk.obj : error LNK2001: unresolved external symbol _asin arithchk.obj : error LNK2001: unresolved external symbol _exp arithchk.obj : error LNK2001: unresolved external symbol _log arithchk.obj : error LNK2001: unresolved external symbol _sqrt arithchk.obj : error LNK2001: unresolved external symbol _acos arithchk.obj : error LNK2019: unresolved external symbol ___iob_func referenced in function _main arithchk.obj : error LNK2019: unresolved external symbol _fprintf referenced in function _main arithchk.obj : error LNK2019: unresolved external symbol _printf referenced in function _ccheck arithchk.obj : error LNK2019: unresolved external symbol __errno referenced in function _main arithchk.obj : error LNK2019: unresolved external symbol @__security_check_cookie@4 referenced in function _Lcheck arithchk.obj : error LNK2019: unresolved external symbol ___security_cookie referenced in function _Lcheck arithchk.obj : error LNK2001: unresolved external symbol __fltused LINK : error LNK2001: unresolved external symbol _mainCRTStartup arithchk.exe : fatal error LNK1120: 13 unresolved externals
LIB和INCLUDE和PATH设置为在命令窗口中运行vcvarsall.bat时的结果。
我无法弄清楚为什么这些符号没有得到解决,并且非常感谢任何帮助。
谢谢, --Laci
更新
如果我打开DOS命令提示符,运行vcvarsall.bat,然后编译,那么它的工作正常。请注意,运行vcvarsall.bat并执行echo %LIB%
和echo %INCLUDE%
后,我获得与上面相同的值。所以问题在于与某个地方的cygwin的互动,只是我无法弄清楚在哪里,但是: - (...
答案 0 :(得分:0)
Cygwin 预先 /usr/local/bin:/usr/bin
到PATH,并且很可能是因为Cygwin的GNU链接工具正在使用,尽管您已经设置了环境。您可以使用echo $PATH
以及link --version
或which link
进行验证。 1
如果是这种情况,则在~/.bash_profile
中定义PATH变量,以便首先找到MSVC链接器。由于Cygwin存储从作为ORIGINAL_PATH启动的Windows环境的完整路径,您可以使用:
# Reorder PATH in .bash_profile
PATH="${ORIGINAL_PATH}/usr/local/bin:/usr/bin"
通过这种方式定义PATH,在与Cygwin实用程序发生冲突的地方,Windows实用程序将优先使用 - official docs提及find
,link
和sort
作为示例。
您可能希望采用更简单的路径并仅使用您需要的项目来定义新的PATH,而不是从Windows获取整个PATH。当然,您可以在.bash_profile
中执行此操作,但也可以在启动Cygwin之前从Cygwin.bat
执行此操作。例如:
:: Minimal path defined in Cygwin.bat. Note the double quotes!
set PATH="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin"
同样,它在Cygwin中存储为ORIGINAL_PATH,然后您更改默认顺序,如上所述。请记住,最小的方法可能会变得有点“小巧”。对于更复杂的场景,当您计算出依赖关系等时。
当我需要使用MSVC或其他Windows实用程序时,我通常更喜欢保持简单并将Cygwin实用程序放在整个 Windows PATH的末尾。但不是总是,我确实喜欢我的工具灵活。在以下最小示例中,修改了标准Cygwin.bat
文件,以便在启动Cygwin时通过命令行参数选择一些预定义的设置。
@echo off
if "%1"=="" (goto run-1)
if "%1"=="-m" (goto prepend-1)
if "%1"=="-w" (goto prepend-2)
if "%1"=="-h" (goto help-1)
:help-1
echo Cygwin.bat: modifed to set PATH via command line arg
echo ARG Description
echo (none) Default - Prepend Cygwin PATH to the full Windows PATH. [CYG,WIN]
echo -m Prepend only MSVC utilities to the Cygwin PATH (minimal approach). [MSVC,CYG]
echo -w Prepend full Windows PATH to the Cygwin PATH. [WIN,CYG]
echo -h Print this help msg and exit.
exit /b
:prepend-1
set MSVC_KW=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin
goto run-1
:prepend-2
set WIN_KW=1
goto run-1
:run-1
C:
chdir C:\cygwin64\bin
bash --login -i
此必须同时重新排序.bash_profile
中的路径,如下所示。
# Modify the default PATH in .bash_profile according to KW from Cygwin.bat
if [ -n "${MSVC_KW}" ] ; then
PATH="${MSVC_KW}:/usr/local/bin:/usr/bin"
export PATH
unset MSVC_KW
elif [ -n "${WIN_KW}" ] ; then
PATH="${ORIGINAL_PATH}:/usr/local/bin:/usr/bin"
export PATH
unset WIN_KW
fi