<code>1、下載和安裝msys2
https://www.msys2.org/
https://sourceforge.net/projects/msys2/
2、安裝編譯工具鏈
pacman -S mingw32/mingw-w64-i686-gcc
pacman -S mingw32/mingw-w64-i686-gdb
pacman -S mingw32/mingw-w64-i686-make
pacman -S mingw32/mingw-w64-i686-cmake
pacman -S mingw64/mingw-w64-x86_64-gcc
pacman -S mingw64/mingw-w64-x86_64-gdb
pacman -S mingw64/mingw-w64-x86_64-make
pacman -S mingw64/mingw-w64-x86_64-cmake
pacman -S msys/gcc
pacman -S msys/gdb
pacman -S msys/make
pacman -S msys/cmake
3、編譯源碼 (以poco-poco-1.9.0-release.tar.gz為例子)
1)雙擊mingw64.exe進入shell
2) tar -xzvf poco-poco-1.9.0-release.tar.gz
3)cd poco-poco-1.9.0-release
4) ./configure --minimal --config=MinGW --no-tests --no-samples --shared --static
5) make
6) make install
4、編譯幫助
./configure --help
usage: configure {options}
Configure the POCO C++ Libraries.
Options:
--help
Display this help screen.
--config=<config>
Use the given build configuration.
Available configurations are:
AIX Darwin-clang MinGW-CrossEnv
Alpine Darwin-clang-libc++ NIOS2-Linux
Android DigiEL OpenPandora
Angstrom ELDK OSF1
AppleTV FreeBSD PPC-Linux
AppleTVSimulator FreeBSD-Linux-compat QNX
ARM-Linux GCCEMBEDLINUX SH-Linux
BeagleBoard HP-UX SmartOS-gcc
CEGCCARM iPhone SSV-LINUX
CygLinux iPhone-clang SunOS
CYGWIN iPhone-clang-libc++ SunOS-GCC
Darwin iPhoneSimulator SunOS-stdcxx-x86_64
Darwin32 iPhoneSimulator-clang SunOS-SunForte
Darwin32-clang iPhoneSimulator-clang-libc++ SunOS-SunStudio
Darwin32-clang-libc++ Linux SunOS-SunStudio11
Darwin64 Linux-clang WatchOS
Darwin64-clang Linux-SolarisStudio WatchSimulator
Darwin64-clang-libc++ MinGW Yocto
--prefix=<install>
Use the given install directory for make install.
Default is /usr/local.
--no-prefix
Do not use /usr/local as default install directory and do not
define POCO_PREFIX.
--stdcxx-base=<apache>
If (and only if) the /home/chenkaibin/local-build/poco-install/poco-poco-1.9.0-release/build/config selected with --config
uses the Apache stdcxx library, then apache_stdcxx_install_prefix
specifies the base directory where stdcxx is installed.
--no-tests
Do not build testsuites.
--no-samples
Do not build samples.
--minimal
Build only Foundation, XML, JSON, Util and Net.
--typical (default)
Build only Foundation, XML, JSON, Util, Net, Crypto, NetSSL, Data/SQLite and Zip.
--everything
Build everything.
--no-wstring
Compile with -DPOCO_NO_WSTRING.
Useful if your C++ compiler does not support std::wstring
(such as uClibc-based systems).
--no-fpenvironment
Compile with -DPOCO_NO_FPENVIRONMENT.
Useful if your C++ compiler has incomplete floating-point support
(such as uClibc-based systems).
--no-sharedmemory
Compile with -DPOCO_NO_SHAREDMEMORY.
For systems that don't support shared memory API's,
like uClibc-based Linux systems.
--no-sharedlibs
Compile with -DPOCO_NO_SHAREDLIBS.
For systems that don't support shared library loading.
--no-ipv6
Compile with -DPOCO_NET_NO_IPv6.
For systems that don't support IPv6.
--sqlite-fts=<path>
Compile with -DPOCO_DATA_SQLITE_FTS.
Compile SQLite with Full Text Search support.
--sqlite-thread-safe=<value>
Compile with -DSQLITE_THREADSAFE=<value>.
Valid values are:
- 0 single-thread, no thread safety
- 1 serial access, highest thread safety
- 2 multi-threaded, without session sharing support
--omit=<component>{,<component>}
Do not build the specified component(s).
Example: --omit=Data/MySQL,Data/ODBC,Zip
--include-path=<path>
Add search path for header files.
--library-path=<path>
Add search path for library files.
--odbc-lib=<path>
Specify the directory where ODBC library is located.
--odbc-include=<path>
Specify the directory where ODBC header files are located.
--cflags=<flags>
Pass additional flags to compiler.
Example: --cflags=-wall
--poquito
Omit a few features for smaller codesize when linking
statically for embedded targets.
--unbundled
Use system-provided zlib, pcre, expat and sqlite instead of
bundled ones.
--static
Build static libraries. Overrides default mode, which
depends upon target. Can be specified together
with --shared to build both.
--shared
Build shared libraries. Overrides default mode, which
depends upon target. Can be specified together
with --static to build both.
5、上面編譯成功
6、使用上面的鏈接庫可能會發現的問題
我自己的項目是cmake項目,一般會cmake -G "MinGW Makefiles" ..
然後自己mingw32-make,結果總是出現以下問題,不知道什麼鬼
undefined reference to `_imp___ZN4Poco17RandomInputStreamC1Ev'
undefined reference to `_imp___ZN4Poco12BinaryReaderC1ERSiNS0_15StreamByteOrderE'
undefined reference to `_imp___ZN4Poco12BinaryReaderrsERm'
undefined reference to `_imp___ZN4Poco12BinaryReaderD1Ev'
undefined reference to `_imp___ZN4Poco17RandomInputStreamD1Ev'
undefined reference to `_imp___ZN4Poco12BinaryReaderD1Ev'
undefined reference to `_imp___ZN4Poco17RandomInputStreamD1Ev
undefined reference to `__imp__ZN4Poco11Environment6osNameB5cxx11Ev'
undefined reference to `__imp__ZN4Poco11Environment13osDisplayNameB5cxx11Ev'
undefined reference to `__imp__ZN4Poco11Environment14osArchitectureB5cxx11Ev'
undefined reference to `__imp__ZN4Poco11Environment9osVersionB5cxx11Ev'
undefined reference to `__imp__ZN4Poco11Environment6isUnixEv'
undefined reference to `__imp__ZN4Poco11Environment9isWindowsEv'
是我自己編譯的庫有問題麼,但是明明成功了,靜態庫都生成了,沒辦法
我把自己編譯的給刪除了,然後用命令安裝了poco,不過不是最新的版本
pacman -S mingw64/mingw-w64-x86_64-poco
編譯自己的項目還是後失敗,總是上面類似的問題,實在沒辦法,我用g++編譯,竟然通過了
g++ main.cpp -o test -lPocoFoundation -lPocoNet
7、猜想原因
1)是不是cmake項目都要用cmake來編譯?
2)查找了資料說mingw編譯的靜態庫有問題?
3)我自己用cmake編譯以下試一試,結果又出現了下面問題
-- The C compiler identification is GNU 9.2.0
-- The CXX compiler identification is GNU 9.2.0
-- Check for working C compiler: C:/CKBSetup/msys64/mingw64/bin/gcc.exe
-- Check for working C compiler: C:/CKBSetup/msys64/mingw64/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:/CKBSetup/msys64/mingw64/bin/g++.exe
-- Check for working CXX compiler: C:/CKBSetup/msys64/mingw64/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.9.0
-- Checking for C++11 compiler
-- Checking for C++11 compiler - available
-- Checking for C++14 compiler
-- Checking for C++14 compiler - available
-- Setting Poco build type - RelWithDebInfo
CMake Error at cmake/PocoMacros.cmake:33 (message):
message compiler not found: required to build
Call Stack (most recent call first):
CMakeLists.txt:86 (include)
-- Configuring incomplete, errors occurred!
See also "C:/CKBSetup/msys64/home/chenkaibin/poco-install/poco-poco-1.9.0-release/cmake-build/CMakeFiles/CMakeOutput.log".
算了,不搞了,太費勁了,今天不搞了,期待大神搞定/<flags>/<path>/<path>/<path>/<path>/<component>/<component>/<value>/<value>/<path>/<apache>/<install>/<config>/<code>
閱讀更多 KIN在路上 的文章