I am running into an issue with compiling gdal 1.11.0 following the guide here: http://trac.osgeo.org/gdal/wiki/BuildingOnWindows
I am able to run nmake /f makefile.vc MSVC_VER=1800 WIN64=YES but when doing the install it fails with the following erros:
Creating library gdal_i.lib and object gdal_i.exp
LINK : error LNK2001: unresolved external symbol _OGRFeatureStylePuller
LINK : error LNK2001: unresolved external symbol _OSRValidate
LINK : error LNK2001: unresolved external symbol _OPTGetProjectionMethods
LINK : error LNK2001: unresolved external symbol _OGR_G_GetPointCount
LINK : error LNK2001: unresolved external symbol _OGRRegisterAll
LINK : error LNK2001: unresolved external symbol _GDALSimpleImageWarp#36
LINK : error LNK2001: unresolved external symbol _GDALReprojectImage#48
LINK : error LNK2001: unresolved external symbol _GDALComputeMedianCutPCT#32
LINK : error LNK2001: unresolved external symbol _GDALDitherRGB2PCT#28
LINK : error LNK2001: unresolved external symbol _OCTNewCoordinateTransformation
#8
gdal111.dll : fatal error LNK1120: 10 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 12.0
\VC\BIN\amd64\link.EXE"' : return code '0x460'
Stop.
Is that something I can do anything about or is it something thats broken in the source downloaded from http://trac.osgeo.org/gdal/wiki/DownloadSource
The answer provided by Poul is not right. I finally find a way to fix this problem:
Find the nmake.opt file under GDAL home folder, open it and search for the definition of 'SYM_PREFIX'. Then change 'SYM_PREFIX=_' to 'SYM_PREFIX=' (remove the underscore).
Find the makefile.vc file under GDAL home folder, open it and search for the first definition of 'BASE_INCLUDE' (The other definition is just below it, do not change the wrong one).
Change from
BASE_INCLUDE = /INCLUDE:_GDALSimpleImageWarp#36 /
/INCLUDE:_GDALReprojectImage#48 /
/INCLUDE:_GDALComputeMedianCutPCT#32 /
/INCLUDE:_GDALDitherRGB2PCT#28 /
/INCLUDE:_OCTNewCoordinateTransformation#8 $(VB6_SAFEARRAYSYM)
to:
BASE_INCLUDE = /INCLUDE:$(SYM_PREFIX)GDALSimpleImageWarp /
/INCLUDE:$(SYM_PREFIX)GDALReprojectImage /
/INCLUDE:$(SYM_PREFIX)GDALComputeMedianCutPCT /
/INCLUDE:$(SYM_PREFIX)GDALDitherRGB2PCT /
/INCLUDE:$(SYM_PREFIX)OCTNewCoordinateTransformation $(VB6_SAFEARRAYSYM)
.
In short, replace the '_' with $(SYM_PREFIX), and remove the '#number'.
According to some webpages, this problem may be caused by the change of AMD64 vc++ compiler handling undecorated symbols.
It turned out that the arguments could not be passed on command line and needed to be changed in the config file.
I have same problem and after set right MSVC_VER(mine VS 2012), problem is solved.
Nmake Command:
nmake /f makefile.vc MSVC_VER=1800 WIN64=yes
MSVC Versions:
MSVC++ 9.0 _MSC_VER == 1500 (Visual Studio 2008)
MSVC++ 10.0 _MSC_VER == 1600 (Visual Studio 2010)
MSVC++ 11.0 _MSC_VER == 1700 (Visual Studio 2012)
MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013)
MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015)
MSVC++ 14.1 _MSC_VER == 1910 (Visual Studio 2017)
You can pass additional arguments into the build by uncommenting parts of the nmake.opt file. The below commands worked for me after invoking the batch file located at
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\"
with vcvarsall.bat amd64
nmake /f makefile.vc MSVC_VER=1800 WIN64=yes
nmake /f makefile.vc install MSVC_VER=1800 WIN64=yes
nmake /f makefile.vc devinstall MSVC_VER=1800 WIN64=yes
Related
I was following the tutorial in LibTorch here.
With the following changes:
example-app => Ceres
example-app.cpp => main.cxx
Everything worked until the CMake command cmake --build . --config Release.
It produced the following errors:
main.obj : error LNK2001: unresolved external symbol __imp___tls_index_?init#?1??lazy_init_num_threads#internal#at##YAXXZ#4_NA [D:\Silverous Black\CPE42S2-CPE42S2\CPE 406\ProjectDumagan\src\Ceres\build\Ceres.vcxproj]
main.obj : error LNK2001: unresolved external symbol __imp___tls_offset_?init#?1??lazy_init_num_threads#internal#at##YAXXZ#4_NA [D:\Silverous Black\CPE42S2-CPE42S2\CPE 406\ProjectDumagan\src\Ceres\build\Ceres.vcxproj]
D:\Silverous Black\CPE42S2-CPE42S2\CPE 406\ProjectDumagan\src\Ceres\build\Release\Ceres.exe : fatal error LNK1120: 2 unresolved externals [D:\Silverous Black\CPE42S2-CPE42S2\CPE 406\ProjectDumagan\src\Ceres\build\Ceres.vcxproj]
I don't believe these are from the changes I placed, since the problem is with the linking.
I also am trying to replicate this directly into Visual Studio. I am using Visual Studio 17 2022 which the LibTorch extension is not yet compatible with (Visual Studio 16 2019 is no longer available for install from the website).
The replication is through a blank C++ template (no starting files). And I have set the following macros:
LibTorchTarget = CPU specifies libtorch for CPU is to be used (useful for other macros
LibTorchDir = C:/libtorch/ directory where the libtorch installation(s) can be found (for multiple installations)
LibTorchInstall = $(LibTorchDir)libtorch_$(LibTorchTarget)/ expresses to C:/libtorch/libtorch_CPU/
LibTorchInclude = $(LibTorchInstall)include/ expresses to C:/libtorch/libtorch_CPU/include/
LibTorchLib = $(LibTorchInstall)lib/ expresses to C:/libtorch/libtorch_CPU/lib/
And have put the Include and Lib macros at their respective VC++ Directories positions. As well as $(LibTorchLib)*.lib (C:/libtorch/libtorch_CPU/lib/*.lib) in the Linker > Input > Additional Dependencies to specify all the .libs for linking (prevents a lot of LNK2009 errors).
And lastly, I have put start xcopy /s "$(LibTorchLib)*.dll" "$(OutDir)" /Y /E /D /R command at the Build Events > Pre-Link Event > Command Line to replicate the if clause in the CMakeLists.txt in the tutorial (apparently to avoid memory errors).
Result is same exact error with a final LNK1120 error:
Error LNK2001 unresolved external symbol __imp___tls_index_?init#?1??lazy_init_num_threads#internal#at##YAXXZ#4_NA Ceres D:\Silverous Black\CPE42S2-CPE42S2\CPE 406\ProjectDumagan\src\Ceres\main.obj 1
Error LNK2001 unresolved external symbol __imp___tls_offset_?init#?1??lazy_init_num_threads#internal#at##YAXXZ#4_NA Ceres D:\Silverous Black\CPE42S2-CPE42S2\CPE 406\ProjectDumagan\src\Ceres\main.obj 1
Error LNK1120 2 unresolved externals Ceres D:\Silverous Black\CPE42S2-CPE42S2\CPE 406\ProjectDumagan\out\Debug_64\Ceres\Ceres.exe 1
I don't exactly understand the reason for the LNK errors, so if anyone could help that'll be really nice. Thank you in advance.
Look to: Updating to Visual Studio 17.4.0 Yields linker errors related to TLS
You most likely need to rebuild PyTorch after MSVC update.
I am working on a solution with 100+ files. I am using MS Visual Studio 2015 Pro. Compiling it is fine, problems come at link stage.
LINK complains on one of the project's library but only gives me the error number.
The command line (simplified) used is the following:
LINK.exe /NOLOGO /MANIFEST /IMPLIB:C:\\MySolution\\myownlib.lib -LARGEADDRESSAWARE -subsystem:console -MACHINE:X86 -DEBUG -INCREMENTAL /DLL File1.cpp.1.o File2.cpp.1.o File3.cpp.1.o File4.cpp.1.o /OUT:C:\\MySolution\\myownlib.dll
The only output I get is the following:
File1.cpp.1.o : error LNK2005:
File2.cpp.1.o : error LNK2005:
File3.cpp.1.o : error LNK2005:
File4.cpp.1.o : error LNK2005:
File1.cpp.1.o : error LNK2001:
File2.cpp.1.o : error LNK2001:
File3.cpp.1.o : error LNK2001:
File4.cpp.1.o : error LNK2001:
I cannot find any clue as to why the linker does not complains with the duplicated symbols nor the unresolved ones. Since the lib owns more than 80 objects, and nearly all of them is listed, finding the erroneous symbol(s) is like looking for a needle in a haystack!
EDIT : I do not compile using the IDE, I use the developer command prompt to build. Migrating the project in Visual Studio is not frankly possible as the program I am working on has never been imported under Visual Studio, we only use the compiler/linker. Moreover, a colleague of mine working on the project does not experience such troubles. It seems that something is going on under my environment...
EDIT 2 : Full installation repair fixed the problem.
I am trying to properly setup CUDA in order to take advantage of the GPU in Theano.
After fixing many compilation problems by tuning my .theanorc and nvcc.profile files, I am struggling to fix this linking error:
mod.cu(735): warning: conversion from pointer to smaller integer
mod.cu(1019): warning: statement is unreachable
mod.cu(735): warning: conversion from pointer to smaller integer
mod.cu(1019): warning: statement is unreachable
mod.cu
Creating library C:/Users/niluje/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_60_Stepping_3_GenuineIntel-2.7.10-64/cuda_ndarray/cuda_ndarray.lib and object C:/Users/niluje/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_60_Stepping_3_GenuineIntel-2.7.10-64/cuda_ndarray/cuda_ndarray.exp
MSVCRT.lib(atonexit.obj) : error LNK2019: unresolved external symbol __imp_EncodePointer referenced in function __atonexitinit
MSVCRT.lib(crtdll.obj) : error LNK2001: unresolved external symbol __imp_EncodePointer
MSVCRT.lib(atonexit.obj) : error LNK2019: unresolved external symbol __imp_DecodePointer referenced in function _onexit
MSVCRT.lib(crtdll.obj) : error LNK2001: unresolved external symbol __imp_DecodePointer
MSVCRT.lib(gs_report.obj) : error LNK2019: unresolved external symbol __imp_IsDebuggerPresent referenced in function __raise_securityfailure
MSVCRT.lib(gs_report.obj) : error LNK2019: unresolved external symbol IsProcessorFeaturePresent referenced in function __report_gsfailure
MSVCRT.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp_QueryPerformanceCounter referenced in function __security_init_cookie
MSVCRT.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp_GetCurrentProcessId referenced in function __security_init_cookie
MSVCRT.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp_GetCurrentThreadId referenced in function __security_init_cookie
MSVCRT.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp_GetSystemTimeAsFileTime referenced in function __security_init_cookie
MSVCRT.lib(dllmain.obj) : error LNK2019: unresolved external symbol __imp_DisableThreadLibraryCalls referenced in function DllMain
C:/Users/niluje/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_60_Stepping_3_GenuineIntel-2.7.10-64/cuda_ndarray/cuda_ndarray.pyd : fatal error LNK1120: 9 unresolved externals
Here's my .theanorcfile:
[global]
device = gpu
floatX = float32
[cuda]
root = C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5
[nvcc]
flags = --use-local-env --cl-version=2013 -LC:\Users\niluje\Anaconda\Lib;
compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64
And here is my nvcc.profile file:
TOP = $(_HERE_)/..
NVVMIR_LIBRARY_DIR = $(TOP)/nvvm/libdevice
PATH += $(TOP)/open64/bin;$(TOP)/nvvm/bin;$(_HERE_);$(TOP)/lib;
INCLUDES += "-I$(TOP)/include" "-IC:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include" "-IC:\Program Files\Microsoft SDKs\Windows\v6.0A\Include" $(_SPACE_)
LIBRARIES =+ $(_SPACE_) "/LIBPATH:$(TOP)/lib/$(_WIN_PLATFORM_)" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\amd64" "/LIBPATH:C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib"
CUDAFE_FLAGS +=
PTXAS_FLAGS +=
It seems that this is not an uncommon error, but generally fixes involve changing some setting in the Visual Studio project. However, here I don't have a Visual Studio project. The code is dynamically generated by Theano and compiled at runtime.
Relevant system settings:
Windows 10 (yes...)
Python 2.7.10 64bits (Anaconda distrib)
CUDA 7.5 / NVIDIA driver 353.54 / GeForce GTX 760
Visual Studio Community 2013
Damn it! I figured it out just after posting the question. The solution: slightly different include and library folders:
TOP = $(_HERE_)/..
NVVMIR_LIBRARY_DIR = $(TOP)/nvvm/libdevice
PATH += $(TOP)/open64/bin;$(TOP)/nvvm/bin;$(_HERE_);$(TOP)/lib;
INCLUDES += "-I$(TOP)/include" "-IC:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include" "-IC:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include" $(_SPACE_)
LIBRARIES =+ $(_SPACE_) "/LIBPATH:$(TOP)/lib/$(_WIN_PLATFORM_)" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\amd64" "/LIBPATH:C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64"
CUDAFE_FLAGS +=
PTXAS_FLAGS +=
In particular I switched from:
C:\Program Files\Microsoft SDKs\Windows\v6.0A\
to:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A
(I thought that I had to use the Program Files ones because of my 64bits project, but in fact the 64bits files are also included in Program Files (x86))
I would also like to thank you. I have been trying to get this working for hours, and this was the post that put me over the edge. My config was slightly different, so my actual links were different. I am posting them in case it helps anyone else
.theanorc
[global]
device = gpu
floatX = float32
[nvcc]
flags = --use-local-env --cl-version=2008
nvcc.profile
TOP = $(_HERE_)/..
NVVMIR_LIBRARY_DIR = $(TOP)/nvvm/libdevice
PATH += $(TOP)/open64/bin;$(TOP)/nvvm/bin;$(_HERE_);$(TOP)/lib;
INCLUDES += "-I$(TOP)/include" "-I$(TOP)/include/cudart" "-IC:/Program Files (x86)/Common Files/Microsoft/Visual C++ for Python/9.0/VC/include" "-IC:\Program Files\Microsoft SDKs\Windows\v7.1\Include"$(_SPACE_)
LIBRARIES =+ $(_SPACE_) "/LIBPATH:$(TOP)/lib/$(_WIN_PLATFORM_)" "/LIBPATH:C:/Program Files (x86)/Common Files/Microsoft/Visual C++ for Python/9.0/VC/lib/amd64" "/LIBPATH:C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\x64"
CUDAFE_FLAGS +=
OPENCC_FLAGS +=
PTXAS_FLAGS +=
using:
windows 7, 64bit
cuda 5.5
python 2.7
windows SDK 7.1
Microsoft Visual C++ Compiler for Python 2.7
I am running CUDA 6.5 on Visual Studio 2013 x64.
I have a VC++ static library project named MyLib which is linked with MyClient x64 console executable project. I added CUDA 6.5 build customization to both the projects. In addition, I goto Configuration Properties -> CUDA C/C++ and have set “Target Machine Platform” as 64-bit for these two projects as I want to compile them for x64 platform
I added MyCUDACode.cpp and MyCUDACode.h files to MyLib project and marked their item type as CUDA C/C++ instead oc C/C++ compiler. MyCUDACode.cpp has number of functions which call CUDA API functions. Also, MyCUDACode.h references the cuda.h and cuda_runtime.h files.
MyClient is linked with MyLib. I now get two compilation errors:
First error in compiling MyLib which says a Unable to create directory
Second, I get unresolved external symbol errors while linking
MyClient with MyLib. Here is the log output:
------ Build started: Project: MyLib, Configuration: Release x64 ------
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\BuildCustomizations\CUDA 6.5.targets(412,9): error MSB3191: Unable to create directory "x64\Release\D:\github\src\helpers\". The given path's format is not supported.
2>------ Build started: Project: MyClient, Configuration: Release x64 ------
2>MyLib.lib(MyCUDACode.obj) : error LNK2001: unresolved external symbol cudaGetDeviceCount
2>MyLib.lib(MyCUDACode.obj) : error LNK2001: unresolved external symbol cudaDeviceCanAccessPeer
2>MyLib.lib(MyCUDACode.obj) : error LNK2001: unresolved external symbol cudaGetDeviceProperties
2>MyLib.lib(MyCUDACode.obj) : error LNK2001: unresolved external symbol cudaSetDevice
2>MyLib.lib(MyCUDACode.obj) : error LNK2001: unresolved external symbol cudaDeviceDisablePeerAccess
2>MyLib.lib(MyCUDACode.obj) : error LNK2001: unresolved external symbol cudaDeviceReset
2>MyLib.lib(MyCUDACode.obj) : error LNK2001: unresolved external symbol cudaDeviceEnablePeerAccess
2>C:...\visual studio 2013\Projects\Prj\x64\Release\MyClient.exe : fatal error LNK1120: 7 unresolved externals
I have tried both release and debug modes but I get same error.
I am just reproducing the steps to resolve the errors:
To resolve the error(temporary workaround): MSB3191: Unable to create directory The given path's format is not supported., simply copy Cuda cu and cuh files to Visual studio project folder.
[UPDATE]: I recently found a better solution for the issue MSB3191: Unable to create directory The given path's format is not supported.. This fix works without need to move around the cu files to the VS project folder. For this, open the file "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\BuildCustomizations\CUDA 6.5.targets", and move to the offending line(412 in this case). This line contains following xml section:
<MakeDir
Condition="'%(CudaCompile.ExcludedFromBuild)' != 'true'"
Directories="%(CudaCompile.DepsOutputDir)" />
As you can see, this is a sort of directive which tells the build system to make a folder for the cuda files being compiled. The property used for folder name is CudaCompile.DepsOutputDir. Now open the file: "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\BuildCustomizations\CUDA 6.5.props". This props file defines values of the properties used in targets file. Now search for word DepsOutputDirin this props file. There are only XML section which defines and refers to this keyword is:
<!-- Miscellaneous -->
<DepsOutputFile>%(Filename)%(Extension).deps</DepsOutputFile>
<DepsOutputDir>$(IntDir)%(RelativeDir)</DepsOutputDir>
<DepsOutputPath>%(DepsOutputDir)%(DepsOutputFile)</DepsOutputPath>
Now, to finally fix the MSB3191 issue, simply remove the variable %(RelativeDir) from above xml section and save the props file (this would require administrative privileges)
To resolve the error: LNK2001: unresolved external symbol, follow the Settings for Linker section in this post
I am attempting to use msbuild to build a Visual Studio 2005 solution. The batch file I am using is:
#ECHO OFF
SETLOCAL
set VSDIR=C:\Program Files (x86)\Microsoft Visual Studio 8
set VCVARSALL=%VSDIR%\VC\vcvarsall.bat
call "%VCVARSALL%" x86 && ^
msbuild path\to\my.sln ^
/v:normal ^
/p:Configuration=Release ^
/p:Platform=Win32 ^
/t:SomeProject:Rebuild
ENDLOCAL
Now, SomeProject depends on SomeOtherProject which is all fine and good except I get unresolved externals when building with msbuild:
SomeObjFile.obj : error LNK2001: unresolved external symbol "private: static class SomeClass<class C> C::s_c" (?s_c#C##0V?$SomeClass#VC####A)
The problem is that when I right-click the project in Visual Studio 2005 and select "Rebuild", I don't get any issue with unresolved externals.
Does anyone know what I might be doing wrong in my invocation of msbuild above?
Thanks!
Figured out the problem with the msbuild version: the project references were missing. To fix this, right-click on the project in VS and add the references to the missing libraries. Save all projects and Bob's your uncle.