Summary of problems encountered during mingw tool compilation

Source: Internet
Author: User
Tags win32

Today, I finally compiled the code written at the Dragon Boat Festival on windows (mingw. The process is still difficult. Here we record it:

1. cmake searches for the boost library on the system. Previously, it directly failed because the FindBoost file only supports up to 1.46.0, and the boost version compiled and installed by itself is 1.46.1. After the boost version supported by this file is modified, the directory can be found, but neither the boost thread nor boost system can be found. The solution is to add the following content to the cmake file:

The code is as follows: Copy code
If (WIN32)
Set (Boost_USE_STATIC_LIBS ON)
Set (Boost_NO_SYSTEM_PATHS ON)
Set (Boost_USE_STATIC_RUNTIME ON)
Endif (WIN32)



Then, let boost forcibly find the static library (previously compiled boost only compiled the static library)

2. When the boost asio Library is linked in windows, you need to specify the win32 socket-related Library. Mingw does not have vs, so it can automatically link to the dependent library based on the static link Library. Therefore, undefined reference will be reported when it is finally linked to an executable program. Solution: add the following in cmake:

The code is as follows: Copy code
If (WIN32)
Find_library (MSwsock mswsock)
Target_link_libraries (http_static MSwsock)
Target_link_libraries (http MSwsock)
Find_library (WS2_32 ws2_32)
Target_link_libraries (http_static WS2_32)
Target_link_libraries (http WS2_32)
ADD_DEFINITIONS (-DBOOST_THREAD_USE_LIB)
Endif (WIN32)



In this way, when the compiling environment is in windows, the mswsock and ws2_32 libraries are automatically linked.

3. Static link of boost thread library. At the end of the link, the boost thread library also reports that some symbols cannot be found. The reason is that boost is trying to link the dynamic link library of the thread library for half a day. Because you do not want this program to run on other windows machines to copy the dll, the solution is already available. Add the macro definition ADD_DEFINITIONS (-DBOOST_THREAD_USE_LIB) and force boost to search for the static link Library.

4. Statically link the gcc and stdc ++ libraries of mingw. After the compiled program is put on another machine, it still reports that the dynamic link library related to libgcc cannot be found, because mingw uses the built-in gcc and c ++ libraries as dynamic links by default. To modify this parameter, you must pass the static-libgcc -static-libstdc1_two parameters to the compiler during compilation. In cmake, you can modify the cmakelists.txt file as follows:

The code is as follows: Copy code
If (WIN32)
Set (CMAKE_CXX_FLAGS "-static-libgcc-static-libstdc ++ ")
Endif (WIN32)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.