I want to build newest Poco C++ Libraries Complete Edition on Windows statically (libraries only Poco::Foundation and Poco::Zip, without samples and tests) for MinGW (which is delivered by QT Creator).
So first I download and unpack the Windows-version library from home page https://pocoproject.org/download/index.html it is now version poco-1.7.8p3-all
Now I have to change MC settings for different configuration than VS, so I have to change file $(POCO_BASE)/cmake/PocoMacros.cmake and after IF
if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio") ... endif ()
add lines:
get_filename_component(sdk_dir "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]" REALPATH)
set(sdk_bindir "${sdk_dir}/bin")
I use CMake command:
cmake -G "MinGW Makefiles" -DENABLE_CRYPTO=OFF -DENABLE_NET=OFF -DENABLE_XML=OFF -DENABLE_DATA=OFF -DENABLE_MONGODB=OFF -DENABLE_PAGECOMPILER=OFF -DENABLE_PAGECOMPILER_FILE2PAGE=OFF -DENABLE_NETSSL=OFF -DPOCO_STATIC=ON -DCMAKE_INSTALL_PREFIX:PATH=C:\Users\user\Desktop\stackPocoStatic\built
Output:
-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is GNU 5.3.0
-- Check for working C compiler: C:/Qt/Tools/mingw530_32/bin/gcc.exe
-- Check for working C compiler: C:/Qt/Tools/mingw530_32/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Qt/Tools/mingw530_32/bin/g++.exe
-- Check for working CXX compiler: C:/Qt/Tools/mingw530_32/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Poco package version: 1.7.8p3-all (2017-06-22)
-- Setting Poco build type - RelWithDebInfo
-- Found message compiler: C:/Program Files/Microsoft SDKs/Windows/v7.1/Bin/MC.Exe
-- Building static libraries
-- Building without tests & samples
-- Build with using internal copy of sqlite, libz, pcre, expat, ...
-- Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing:
OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR)
-- CMake 3.8.2 successfully configured Poco using MinGW Makefiles generator
-- Installation target path: C:/Users/user/Desktop/stackPocoStatic/built
-- C_FLAGS: =
-- CMAKE_C_FLAGS_DEBUG:=-g -D_DEBUG
-- CMAKE_C_FLAGS_RELEASE:=-O3 -DNDEBUG
-- CMAKE_C_FLAGS_MINSIZEREL:=-Os -DNDEBUG
-- CMAKE_C_FLAGS_RELWITHDEBINFO:=-O2 -g -DNDEBUG
--
--
-- CXX_FLAGS:=
-- CMAKE_CXX_FLAGS_DEBUG:=-g -D_DEBUG
-- CMAKE_CXX_FLAGS_RELEASE:=-O3 -DNDEBUG
-- CMAKE_CXX_FLAGS_MINSIZEREL:=-Os -DNDEBUG
-- CMAKE_CXX_FLAGS_RELWITHDEBINFO:=-O2 -g -DNDEBUG
-- Building: XML
-- Building: JSON
-- Building: Util
-- Building: Net
-- Building: Zip
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/user/Desktop/stackPocoStatic/poco-1.7.8p3-all
then I run make:
PS C:\Users\user\Desktop\stackPocoStatic\poco-1.7.8p3-all> mingw32-make.exe
[ 43%] Built target Foundation
[ 60%] Built target XML
[ 63%] Built target JSON
[ 70%] Built target Util
[ 94%] Built target Net
[100%] Built target Zip
PS C:\Users\user\Desktop\stackPocoStatic\poco-1.7.8p3-all> mingw32-make.exe install
...
and it looks OK, so then I want to compile and run code e.g.:
#include <iostream>
#include <fstream>
#include <Poco/Zip/Compress.h>
int main( int argc, char * argv[] )
{
std::ofstream outputZipArchive("archive.zip", std::ios::binary);
Poco::Zip::Compress compressor( outputZipArchive, true );
for( unsigned i = 1; i < argc; ++i )
{
const char * fileToZip = argv[i];
std::cout << i << ") Adding: " << fileToZip << std::endl;
try
{
compressor.addFile( fileToZip, fileToZip );
}
catch(const Poco::FileNotFoundException & e)
{
std::cerr << "Can not add file " << fileToZip << ", because: " << e.what() << std::endl;
}
}
compressor.close();
outputZipArchive.close();
}
during compilation I see linking error:
PS C:\Users\user\Desktop> g++.exe z.cc -isystemC:\Users\user\Desktop\stackPocoStatic\built\include -LC:\Users\user\Desktop\stackPocoStatic\built\lib\ -lPocoFoundation -lPocoZip
C:\Users\user\AppData\Local\Temp\ccg0K4lf.o:z.cc:(.text+0x57): undefined reference to `_imp___ZN4Poco3Zip8CompressC1ERSob'
C:\Users\user\AppData\Local\Temp\ccg0K4lf.o:z.cc:(.text+0xda): undefined reference to `_imp___ZN4Poco4PathC1EPKc'
C:\Users\user\AppData\Local\Temp\ccg0K4lf.o:z.cc:(.text+0xf2): undefined reference to `_imp___ZN4Poco4PathC1EPKc'
C:\Users\user\AppData\Local\Temp\ccg0K4lf.o:z.cc:(.text+0x127): undefined reference to `_imp___ZN4Poco3Zip8Compress7addFileERKNS_4PathES4_NS0_9ZipCommon17CompressionMethodENS5_16CompressionLevelE'
C:\Users\user\AppData\Local\Temp\ccg0K4lf.o:z.cc:(.text+0x139): undefined reference to `_imp___ZN4Poco4PathD1Ev'
C:\Users\user\AppData\Local\Temp\ccg0K4lf.o:z.cc:(.text+0x148): undefined reference to `_imp___ZN4Poco4PathD1Ev'
C:\Users\user\AppData\Local\Temp\ccg0K4lf.o:z.cc:(.text+0x166): undefined reference to `_imp___ZN4Poco3Zip8Compress5closeEv'
C:\Users\user\AppData\Local\Temp\ccg0K4lf.o:z.cc:(.text+0x175): undefined reference to `_imp___ZN4Poco3Zip10ZipArchiveD1Ev'
C:\Users\user\AppData\Local\Temp\ccg0K4lf.o:z.cc:(.text+0x191): undefined reference to `_imp___ZN4Poco3Zip8CompressD1Ev'
C:\Users\user\AppData\Local\Temp\ccg0K4lf.o:z.cc:(.text+0x1bb): undefined reference to `_imp___ZN4Poco4PathD1Ev'
C:\Users\user\AppData\Local\Temp\ccg0K4lf.o:z.cc:(.text+0x1d0): undefined reference to `_imp___ZN4Poco4PathD1Ev'
C:\Users\user\AppData\Local\Temp\ccg0K4lf.o:z.cc:(.text+0x276): undefined reference to `_imp___ZN4Poco3Zip8CompressD1Ev'
collect2.exe: error: ld returned 1 exit status
The interesting thing is when I run ./configure without option -DPOCO_STATIC=ON:
cmake -G "MinGW Makefiles" -DENABLE_CRYPTO=OFF -DENABLE_NET=OFF -DENABLE_XML=OFF -DENABLE_DATA=OFF -DENABLE_MONGODB=OFF -DENABLE_PAGECOMPILER=OFF -DENABLE_PAGECOMPILER_FILE2PAGE=OFF -DENABLE_NETSSL=OFF -DCMAKE_INSTALL_PREFIX:PATH=C:\Users\user\Desktop\stackPocoDynamic\built
then
mingw32-make.exe && mingw32-make.exe install
then compile:
PS C:\Users\user\Desktop> g++.exe z.cc -isystemC:\Users\user\Desktop\stackPocoDynamic\built\include -LC:\Users\user\Desk
top\stackPocoDynamic\built\lib\ -lPocoFoundation -lPocoZip
there are no linking errors. Of course this time I need .dlls (libPocoZip.dll and libPocoFoundation.dll) to run code:
.\a.exe file.txt
1) Adding: file.txt
Of course I've tried: Static and Dynamic/Shared Linking with MinGW -Wl,-Bstatic:
PS C:\Users\user\Desktop> g++.exe -Bstatic z.cc -isystemC:\Users\user\Desktop\stackPocoStatic\built\include -LC:\Users\user\Desktop\stackPocoStatic\built\lib\ -lPocoFoundation -lPocoZip
I've also tried to add option -static: Statically linking libraries in MinGW
PS C:\Users\user\Desktop> g++.exe z.cc -static -isystemC:\Users\user\Desktop\stackPocoStatic\built\include -LC:\Users\us
er\Desktop\stackPocoStatic\built\lib\ -lPocoFoundation -lPocoZip
Unfortunately there are still linking errors.
I've noticed similar linking errors when compiling with MSYS on Windows:
./configure --static --no-tests --no-sharedlibs --omit=XML,JSON,Util,NetSSL_OpenSSL,Data,Data/SQLite,Data/ODBC,Data/MySQL,MongoDB,PageCompiler,PageCompiler/File2Page,Crypto,PDF,CppParser --config=MinGW
So My question is: Is it possible to compile POCO C++ libraries for MinGW statically on Windows?