Archived issue #0029377
Configuration, CMake - linkage errors while using static OCCT libraries on Windows platform
Description
The following linkage errors occur while trying to use static OCCT libraries within application:
The reason is a weird combination of dllimport/dllexport by OCCT toolkits - seems to be by C functions first of all exported by __Standard_API/__Draw_API etc specific to Windows.
There is a special macros HAVE_NO_DLL which is intended to disable these dllimport/dllexport, however this macros is not defined by any build procedure, including CMake scripts.
1>Link: 1> Creating library C:\OccTest\bin64\Release\OccTest.lib and object C:\OccTest\bin64\Release\OccTest.exp 1>TKLCAF.lib(TDataStd_HDataMapOfStringString.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) int __cdecl HashCode(unsigned short const * const,int)" (__imp_?HashCode@@YAHQEBGH@Z) 1>TKCDF.lib(CDM_Document.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) int __cdecl HashCode(unsigned short const * const,int)" (__imp_?HashCode@@YAHQEBGH@Z) 1>TKCDF.lib(CDM_MetaData.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) int __cdecl HashCode(unsigned short const * const,int)" (__imp_?HashCode@@YAHQEBGH@Z) 1>TKCDF.lib(CDF_Application.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) int __cdecl HashCode(unsigned short const * const,int)" (__imp_?HashCode@@YAHQEBGH@Z) 1>TKLCAF.lib(TDataStd_HDataMapOfStringHArray1OfInteger.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) int __cdecl HashCode(unsigned short const * const,int)" (__imp_?HashCode@@YAHQEBGH@Z) 1>TKLCAF.lib(TDataStd_HDataMapOfStringHArray1OfReal.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) int __cdecl HashCode(unsigned short const * const,int)" (__imp_?HashCode@@YAHQEBGH@Z) 1>TKLCAF.lib(TDataStd_HDataMapOfStringInteger.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) int __cdecl HashCode(unsigned short const * const,int)" (__imp_?HashCode@@YAHQEBGH@Z) 1>TKLCAF.lib(TDataStd_HDataMapOfStringReal.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) int __cdecl HashCode(unsigned short const * const,int)" (__imp_?HashCode@@YAHQEBGH@Z) 1>TKBinL.lib(BinMDataStd_NamedDataDriver.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) int __cdecl HashCode(unsigned short const * const,int)" (__imp_?HashCode@@YAHQEBGH@Z) 1>TKLCAF.lib(TDocStd_Application.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) int __cdecl HashCode(unsigned short const * const,int)" (__imp_?HashCode@@YAHQEBGH@Z) 1>TKLCAF.lib(TDataStd_NamedData.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) int __cdecl HashCode(unsigned short const * const,int)" (__imp_?HashCode@@YAHQEBGH@Z) 1>TKLCAF.lib(TDataStd_HDataMapOfStringByte.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) int __cdecl HashCode(unsigned short const * const,int)" (__imp_?HashCode@@YAHQEBGH@Z) 1>C:\OccTest\bin64\Release\OccTest.dll : fatal error LNK1120: 1 unresolved externals
The reason is a weird combination of dllimport/dllexport by OCCT toolkits - seems to be by C functions first of all exported by __Standard_API/__Draw_API etc specific to Windows.
There is a special macros HAVE_NO_DLL which is intended to disable these dllimport/dllexport, however this macros is not defined by any build procedure, including CMake scripts.
Steps to reproduce
@echo OFF rem Auxiliary script for semi-automated building of OCCT for vc10-64 platform (static libraries). rem Script should be placed into root of OCCT repository, edited with paths to CMake and 3rd-parties. rem CMake can be downloaded from official site: rem https://cmake.org/download/ set "aCasSrc=%~dp0" set aNbJobs=%NUMBER_OF_PROCESSORS% set "PATH=c:\work\Develop\SDKs\CMake\bin;%PATH%" set "aFreeType=c:/workssd/Develop/3rdparty/vc10/freetype-2.7.1-vc10-64" set "aTclTk=c:/workssd/Develop/3rdparty/vc10/tcltk-86-64" set "aFreeImage=c:/workssd/Develop/3rdparty/vc10/freeimage-3.17.0-vc10-64" set "DevEnvDir=%VS100COMNTOOLS%..\IDE" call :cmakeGenerate pause goto :eof :cmakeGenerate set "aPlatformAndCompiler=vc10-64-static" set "aWorkDir=work\%aPlatformAndCompiler%-make" set "aLogFile=%~dp0build-%aPlatformAndCompiler%.log" if not exist "%aWorkDir%" ( mkdir "%aWorkDir%" ) if exist "%aLogFile%" ( del "%aLogFile%" ) pushd "%aWorkDir%" set STARTTIME=%TIME% echo Configuring OCCT for MinGW-w64... cmake -G "Visual Studio 10 2010 Win64" ^ -D CMAKE_BUILD_TYPE:STRING="Release" ^ -D BUILD_LIBRARY_TYPE:STRING="Static" ^ -D BUILD_MODULE_Draw:BOOL="OFF" ^ -D BUILD_MODULE_MfcSamples:BOOL="OFF" ^ -D INSTALL_DIR:PATH="%~dp0work/%aPlatformAndCompiler%" ^ -D INSTALL_DIR_INCLUDE:STRING="inc" ^ -D INSTALL_DIR_RESOURCE:STRING="src" ^ -D 3RDPARTY_FREETYPE_DIR:PATH="%aFreeType%" ^ -D 3RDPARTY_FREETYPE_INCLUDE_DIR_freetype2:FILEPATH="%aFreeType%/include" ^ -D 3RDPARTY_FREETYPE_INCLUDE_DIR_ft2build:FILEPATH="%aFreeType%/include" ^ -D 3RDPARTY_FREETYPE_LIBRARY_DIR:PATH="%aFreeType%/lib" ^ -D 3RDPARTY_TCL_DIR:PATH="%aTclTk%" ^ -D 3RDPARTY_TCL_INCLUDE_DIR:FILEPATH="%aTclTk%/include" ^ -D 3RDPARTY_TCL_LIBRARY_DIR:PATH="%aTclTk%/lib" ^ -D 3RDPARTY_TCL_DLL_DIR:PATH="%aTclTk%/bin" ^ -D 3RDPARTY_TK_DIR:PATH="%aTclTk%" ^ -D 3RDPARTY_TK_INCLUDE_DIR:FILEPATH="%aTclTk%/include" ^ -D 3RDPARTY_TK_LIBRARY_DIR:PATH="%aTclTk%/lib" ^ -D 3RDPARTY_TK_DLL_DIR:PATH="%aTclTk%/bin" ^ -D USE_D3D:BOOL="ON" ^ -D USE_FREEIMAGE:BOOL="ON" ^ -D 3RDPARTY_FREEIMAGE_DIR:PATH="%aFreeImage%" ^ -D 3RDPARTY_FREEIMAGE_INCLUDE_DIR:FILEPATH="%aFreeImage%/include" ^ -D 3RDPARTY_FREEIMAGE_LIBRARY_DIR:PATH="%aFreeImage%/lib" ^ "%aCasSrc%" if errorlevel 1 ( popd pause exit /B goto :eof ) set "PRJFILE=%~dp0%aWorkDir%\OCCT.sln" "%DevEnvDir%\devenv.com" "%PRJFILE%" /clean "Release|x64" echo Building OCCT... "%DevEnvDir%\devenv.com" "%PRJFILE%" /build "Release|x64" 2>> %aLogFile% type %aLogFile% if errorlevel 1 ( popd pause exit /B goto :eof ) rem echo Installing OCCT into %~dp0work/%aPlatformAndCompiler%... set ENDTIME=%TIME% rem handle time before 10AM (win10 - remove empty space at the beginning) if "%STARTTIME:~0,1%"==" " set "STARTTIME=%STARTTIME:~1%" if "%ENDTIME:~0,1%"==" " set "ENDTIME=%ENDTIME:~1%" rem handle time before 10AM (win7 - add 0 at the beginning) if "%STARTTIME:~1,1%"==":" set "STARTTIME=0%STARTTIME%" if "%ENDTIME:~1,1%"==":" set "ENDTIME=0%ENDTIME%" rem convert hours:minutes:seconds:ms into duration set /A STARTTIME=(1%STARTTIME:~0,2%-100)*360000 + (1%STARTTIME:~3,2%-100)*6000 + (1%STARTTIME:~6,2%-100)*100 + (1%STARTTIME:~9,2%-100) set /A ENDTIME= (1%ENDTIME:~0,2%-100)*360000 + (1%ENDTIME:~3,2%-100)*6000 + (1%ENDTIME:~6,2%-100)*100 + (1%ENDTIME:~9,2%-100) set /A DURATION=%ENDTIME%-%STARTTIME% if %ENDTIME% LSS %STARTTIME% set set /A DURATION=%STARTTIME%-%ENDTIME% set /A DURATIONH=%DURATION% / 360000 set /A DURATIONM=(%DURATION% - %DURATIONH%*360000) / 6000 set /A DURATIONS=(%DURATION% - %DURATIONH%*360000 - %DURATIONM%*6000) / 100 if %DURATIONH% LSS 10 set DURATIONH=0%DURATIONH% if %DURATIONM% LSS 10 set DURATIONM=0%DURATIONM% if %DURATIONS% LSS 10 set DURATIONS=0%DURATIONS% echo Building time: %DURATIONH%:%DURATIONM%:%DURATIONS% for %anAbi% echo Building time: %DURATIONH%:%DURATIONM%:%DURATIONS% >> %aLogFile% popd goto :eof
Public activity
4 archived notes
Participants are labeled by their role within this record.
Branch [archived branch] has been created by Author.
[revision removed]
Detailed log of new commits:
Author: Author
Date: Fri Dec 8 15:13:14 2017 +0300
0029377: Configuration, CMake - linkage errors while using static OCCT libraries on Windows platform
HAVE_NO_DLL is now defined when building Static libraries.
[revision removed]
Detailed log of new commits:
Author: Author
Date: Fri Dec 8 15:13:14 2017 +0300
0029377: Configuration, CMake - linkage errors while using static OCCT libraries on Windows platform
HAVE_NO_DLL is now defined when building Static libraries.
Patch is ready for review.
HAVE_NO_DLL should be also defined at application level to avoid linkage working like:
It might be reasonable renaming macros HAVE_NO_DLL to OCCT_NO_DLL for consistency with other macros,
but this should be documented change since, apparently, some advanced users are already using it.
Making a "Static" build with HAVE_NO_DLL also reduces building time from 00:20:54 to 00:16:51.
HAVE_NO_DLL should be also defined at application level to avoid linkage working like:
1>OccTest.obj : warning LNK4049: locally defined symbol ?HashCode@@YAHQEBDH@Z (int __cdecl HashCode(char const * const,int)) imported
It might be reasonable renaming macros HAVE_NO_DLL to OCCT_NO_DLL for consistency with other macros,
but this should be documented change since, apparently, some advanced users are already using it.
Making a "Static" build with HAVE_NO_DLL also reduces building time from 00:20:54 to 00:16:51.
Reviewed, please integrate.
Other corrections related to static builds should be made within #22651
Other corrections related to static builds should be made within #22651
Branch [archived branch] has been deleted by Author.
[revision removed]
[revision removed]
Related records