Cmake Gcc

I believe that CMake 3 had the bad luck to follow Python 3. 1 Even though every version of CMake is insanely backward compatible, the 3 series was treated as if it were something new. And so, you'll find OSs like CentOS7 with GCC 4.8, with almost-complete C14 support, and CMake 2.8, which came out years before C11. CMake 指定gcc编译版本. 素炒瓢儿白: 不用 export 出来,只需要在里面添加如下命令就好: SET(CMAKESYSTEMNAME Linux) // 如果是 windows 则 linux-windows. CMake 指定gcc编译版本. 不是Gonga 回复 zhuiyuanqingya: 感谢,之前一直不明白交叉编译不生效的原因. CMake 指定gcc编译版本.

If cmake(1) is invoked with the command line parameter-DCMAKE_TOOLCHAIN_FILE=path/to/file, the file will be loaded early to setvalues for the compilers.The CMAKE_CROSSCOMPILING variable is set to true when CMake iscross-compiling.

Note that using the CMAKE_SOURCE_DIR or CMAKE_BINARY_DIRvariables inside a toolchain file is typically undesirable. The toolchainfile is used in contexts where these variables have different values when usedin different places (e.g. as part of a call to try_compile()). In mostcases, where there is a need to evaluate paths inside a toolchain file, the moreappropriate variable to use would be CMAKE_CURRENT_LIST_DIR, sinceit always has an unambiguous, predictable value.

A typical cross-compiling toolchain for Linux has content suchas:

The CMAKE_SYSTEM_NAME is the CMake-identifier of the target platformto build for.


The CMAKE_SYSTEM_PROCESSOR is the CMake-identifier of the target architectureto build for.

The CMAKE_SYSROOT is optional, and may be specified if a sysrootis available.

The CMAKE_STAGING_PREFIX is also optional. It may be used to specifya path on the host to install to. The CMAKE_INSTALL_PREFIX is alwaysthe runtime installation location, even when cross-compiling.

The _COMPILER'>CMAKE_<LANG>_COMPILER variables may be set to full paths, or tonames of compilers to search for in standard locations. For toolchains thatdo not support linking binaries without custom flags or scripts one may setthe CMAKE_TRY_COMPILE_TARGET_TYPE variable to STATIC_LIBRARYto tell CMake not to try to link executables during its checks.

CMake find_* commands will look in the sysroot, and the CMAKE_FIND_ROOT_PATHentries by default in all cases, as well as looking in the host system root prefix.Although this can be controlled on a case-by-case basis, when cross-compiling, itcan be useful to exclude looking in either the host or the target for particularartifacts. Generally, includes, libraries and packages should be found in thetarget system prefixes, whereas executables which must be run as part of the buildshould be found only on the host and not on the target. This is the purpose ofthe CMAKE_FIND_ROOT_PATH_MODE_* variables.

Cross compiling for compute nodes in the Cray Linux Environment can be donewithout needing a separate toolchain file. Specifying-DCMAKE_SYSTEM_NAME=CrayLinuxEnvironment on the CMake command line willensure that the appropriate build settings and search paths are configured.The platform will pull its configuration from the current environmentvariables and will configure a project to use the compiler wrappers from theCray Programming Environment's PrgEnv-* modules if present and loaded.

The default configuration of the Cray Programming Environment is to onlysupport static libraries. This can be overridden and shared librariesenabled by setting the CRAYPE_LINK_TYPE environment variable todynamic.

Running CMake without specifying CMAKE_SYSTEM_NAME willrun the configure step in host mode assuming a standard Linux environment.If not overridden, the PrgEnv-* compiler wrappers will end up getting used,which if targeting the either the login node or compute node, is likely not thedesired behavior. The exception to this would be if you are building directlyon a NID instead of cross-compiling from a login node. If trying to buildsoftware for a login node, you will need to either first unload thecurrently loaded PrgEnv-* module or explicitly tell CMake to use thesystem compilers in /usr/bin instead of the Cray wrappers. If insteadtargeting a compute node is desired, just specify theCMAKE_SYSTEM_NAME as mentioned above.

Cmake wx. Some compilers such as Clang are inherently cross compilers.The _COMPILER_TARGET'>CMAKE_<LANG>_COMPILER_TARGET can be set to pass avalue to those supported compilers when compiling:

Similarly, some compilers do not ship their own supplementary utilitiessuch as linkers, but provide a way to specify the location of the externaltoolchain which will be used by the compiler driver. The_COMPILER_EXTERNAL_TOOLCHAIN'>CMAKE_<LANG>_COMPILER_EXTERNAL_TOOLCHAIN variable can be set in atoolchain file to pass the path to the compiler driver.

As the Clang compiler the QNX QCC compile is inherently a cross compiler.And the _COMPILER_TARGET'>CMAKE_<LANG>_COMPILER_TARGET can be set to pass avalue to those supported compilers when compiling:

Cross compiling for Windows CE requires the corresponding SDK beinginstalled on your system. These SDKs are usually installed underC:/ProgramFiles(x86)/WindowsCETools/SDKs.

A toolchain file to configure a Visual Studio generator forWindows CE may look like this:

The CMAKE_GENERATOR_PLATFORM tells the generator which SDK to use.Further CMAKE_SYSTEM_VERSION tells the generator what version ofWindows CE to use. Currently version 8.0 (Windows Embedded Compact 2013) issupported out of the box. Other versions may require one to setCMAKE_GENERATOR_TOOLSET to the correct value.

A toolchain file to configure a Visual Studio generator for aWindows 10 Universal Application may look like this:

A Windows 10 Universal Application targets both Windows Store andWindows Phone. Specify the CMAKE_SYSTEM_VERSION variableto be 10.0 to build with the latest available Windows 10 SDK.Specify a more specific version (e.g. 10.0.10240.0 for RTM)to build with the corresponding SDK.

A toolchain file to configure a Visual Studio generator forWindows Phone may look like this:

A toolchain file to configure a Visual Studio generator forWindows Store may look like this:

A toolchain file may configure cross-compiling for Android by setting theCMAKE_SYSTEM_NAME variable to Android. Further configurationis specific to the Android development environment to be used.

For Visual Studio Generators, CMake expects NVIDIA Nsight TegraVisual Studio Edition or the Visual Studio tools for Android to be installed. See those sectionsfor further configuration details.

For Makefile Generators and the Ninja generator,CMake expects one of these environments:

CMake uses the following steps to select one of the environments:

Cmake Specify Gcc Version

  • If the CMAKE_ANDROID_NDK variable is set, the NDK at thespecified location will be used.

  • Else, if the CMAKE_ANDROID_STANDALONE_TOOLCHAIN variableis set, the Standalone Toolchain at the specified location will be used.

  • Else, if the CMAKE_SYSROOT variable is set to a directoryof the form <ndk>/platforms/android-<api>/arch-<arch>, the <ndk>part will be used as the value of CMAKE_ANDROID_NDK and theNDK will be used.

  • Else, if the CMAKE_SYSROOT variable is set to a directory of theform <standalone-toolchain>/sysroot, the <standalone-toolchain> partwill be used as the value of CMAKE_ANDROID_STANDALONE_TOOLCHAINand the Standalone Toolchain will be used.

  • Else, if a cmake variable ANDROID_NDK is set it will be usedas the value of CMAKE_ANDROID_NDK, and the NDK will be used.

  • Else, if a cmake variable ANDROID_STANDALONE_TOOLCHAIN is set, it will beused as the value of CMAKE_ANDROID_STANDALONE_TOOLCHAIN, and theStandalone Toolchain will be used.

  • Else, if an environment variable ANDROID_NDK_ROOT orANDROID_NDK is set, it will be used as the value ofCMAKE_ANDROID_NDK, and the NDK will be used.

  • Else, if an environment variable ANDROID_STANDALONE_TOOLCHAIN isset then it will be used as the value ofCMAKE_ANDROID_STANDALONE_TOOLCHAIN, and the StandaloneToolchain will be used.

  • Else, an error diagnostic will be issued that neither the NDK orStandalone Toolchain can be found.

New in version 3.20: If an Android NDK is selected, its version number is reportedin the CMAKE_ANDROID_NDK_VERSION variable.

A toolchain file may configure Makefile Generators,Ninja Generators, or Visual Studio Generators to targetAndroid for cross-compiling.

Configure use of an Android NDK with the following variables:


Set to Android. Must be specified to enable cross compilingfor Android.


Set to the Android API level. If not specified, the value isdetermined as follows:

  • If the CMAKE_ANDROID_API variable is set, its valueis used as the API level.

  • If the CMAKE_SYSROOT variable is set, the API level isdetected from the NDK directory structure containing the sysroot.

  • Otherwise, the latest API level available in the NDK is used.


Set to the Android ABI (architecture). If not specified, thisvariable will default to the first supported ABI in the list ofarmeabi, armeabi-v7a and arm64-v8a.The CMAKE_ANDROID_ARCH variable will be computedfrom CMAKE_ANDROID_ARCH_ABI automatically.Also see the CMAKE_ANDROID_ARM_MODE andCMAKE_ANDROID_ARM_NEON variables.


Set to the absolute path to the Android NDK root directory.If not specified, a default for this variable will be chosenas specified above.


Set to a true value to use the deprecated per-api-level headersinstead of the unified headers. If not specified, the default willbe false unless using a NDK that does not provide unified headers.


On NDK r19 or above, this variable must be unset or set to clang.On NDK r18 or below, set this to the version of the NDK toolchain tobe selected as the compiler. If not specified, the default will bethe latest available GCC toolchain.


Set to specify which C++ standard library to use. If not specified,a default will be selected as described in the variable documentation.

The following variables will be computed and provided automatically:


The absolute path prefix to the binutils in the NDK toolchain.


The host platform suffix of the binutils in the NDK toolchain.

For example, a toolchain file might contain:

Alternatively one may specify the values without a toolchain file:

A toolchain file may configure Makefile Generators or theNinja generator to target Android for cross-compilingusing a standalone toolchain.

Configure use of an Android standalone toolchain with the following variables:


Set to Android. Must be specified to enable cross compilingfor Android.


Set to the absolute path to the standalone toolchain root directory.A ${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/sysroot directorymust exist.If not specified, a default for this variable will be chosenas specified above.


When the standalone toolchain targets ARM, optionally set this to ONto target 32-bit ARM instead of 16-bit Thumb.See variable documentation for details.


When the standalone toolchain targets ARM v7, optionally set thisto ONto target ARM NEON devices. See variable documentation for details.

The following variables will be computed and provided automatically:


The Android API level detected from the standalone toolchain.


The Android ABI detected from the standalone toolchain.


The absolute path prefix to the binutils in the standalone toolchain.


The host platform suffix of the binutils in the standalone toolchain.

For example, a toolchain file might contain:

Alternatively one may specify the values without a toolchain file:

A toolchain file to configure one of the Visual Studio Generatorsto build using NVIDIA Nsight Tegra targeting Android may look like this:

The CMAKE_GENERATOR_TOOLSET may be set to selectthe Nsight Tegra 'Toolchain Version' value.

See also target properties:


















For cross-compiling to iOS, tvOS, or watchOS, the Xcodegenerator is recommended. The UnixMakefiles orNinja generators can also be used, but they require theproject to handle more areas like target CPU selection and code signing.

Any of the three systems can be targeted by setting theCMAKE_SYSTEM_NAME variable to a value from the table below.By default, the latest Device SDK is chosen. As for all Apple platforms,a different SDK (e.g. a simulator) can be selected by setting theCMAKE_OSX_SYSROOT variable, although this should rarely benecessary (see Switching Between Device and Simulator below).A list of available SDKs can be obtained by running xcodebuild-showsdks.



Device SDK (default)

Simulator SDK













For example, to create a CMake configuration for iOS, the followingcommand is sufficient:

Variable CMAKE_OSX_ARCHITECTURES can be used to set architecturesfor both device and simulator. Variable CMAKE_OSX_DEPLOYMENT_TARGETcan be used to set an iOS/tvOS/watchOS deployment target.

Next configuration will install fat 5 architectures iOS libraryand add the -miphoneos-version-min=9.3/-mios-simulator-version-min=9.3flags to the compiler:



Check library:

Some build artifacts for the embedded Apple platforms require mandatorycode signing. If the Xcode generator is being used andcode signing is required or desired, the development team ID can bespecified via the CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM CMake variable.This team ID will then be included in the generated Xcode project.By default, CMake avoids the need for code signing during the internalconfiguration phase (i.e compiler ID and feature detection).

When configuring for any of the embedded platforms, one can target eitherreal devices or the simulator. Both have their own separate SDK, but CMakeonly supports specifying a single SDK for the configuration phase. Thismeans the developer must select one or the other at configuration time.When using the Xcode generator, this is less of a limitationbecause Xcode still allows you to build for either a device or a simulator,even though configuration was only performed for one of the two. Fromwithin the Xcode IDE, builds are performed for the selected 'destination'platform. When building from the command line, the desired sdk can bespecified directly by passing a -sdk option to the underlying buildtool (xcodebuild). For example:

Please note that checks made during configuration were performed againstthe configure-time SDK and might not hold true for other SDKs. Commandslike find_package(), find_library(), etc. store and usedetails only for the configured SDK/platform, so they can be problematicif wanting to switch between device and simulator builds. You can followthe next rules to make device + simulator configuration work:

  • Use explicit -l linker flag,e.g. target_link_libraries(fooPUBLIC'-lz')

  • Use explicit -framework linker flag,e.g. target_link_libraries(fooPUBLIC'-frameworkCoreFoundation')

  • Use find_package() only for libraries installed withCMAKE_IOS_INSTALL_COMBINED feature

Hi, I am trying to create a c++ project from existing source, but I am stuck with an error during the pre-build process and I can’t figure out what leads to it. The first one is a CMakeError, which is shown below:

Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
Change Dir: E:/Yifan/Hiwi-FSD/FluCo1/Libraries/fsd-libs/trunk/build-dev/CMakeFiles/CMakeTmp

Run Build Command(s):C:/MinGW/msys/1.0/bin/make.exe -f Makefile cmTC_394d9/fast && /usr/bin/make -f CMakeFiles/cmTC_394d9.dir/build.make CMakeFiles/cmTC_394d9.dir/build
make[1]: Entering directory `/e/Yifan/Hiwi-FSD/FluCo1/Libraries/fsd-libs/trunk/build-dev/CMakeFiles/CMakeTmp’
Building C object CMakeFiles/cmTC_394d9.dir/src.c.obj

E:/Yifan/Hiwi-FSD/FluCo1/Libraries/fsd-libs/trunk/nbproject/private/tools/localhost/MinGW/gcc.exe -DCMAKE_HAVE_LIBC_PTHREAD -o CMakeFiles/cmTC_394d9.dir/src.c.obj -c E:/Yifan/Hiwi-FSD/FluCo1/Libraries/fsd-libs/trunk/build-dev/CMakeFiles/CMakeTmp/src.c
E:/Yifan/Hiwi-FSD/FluCo1/Libraries/fsd-libs/trunk/build-dev/CMakeFiles/CMakeTmp/src.c: In function ‘main’:
E:/Yifan/Hiwi-FSD/FluCo1/Libraries/fsd-libs/trunk/build-dev/CMakeFiles/CMakeTmp/src.c:15:3: warning: implicit declaration of function ‘pthread_atfork’; did you mean ‘pthread_join’? [-Wimplicit-function-declaration]
15 pthread_atfork(NULL, NULL, NULL);
Linking C executable cmTC_394d9.exe

“C:/Program Files/CMake/bin/cmake.exe” -E rm -f CMakeFiles/cmTC_394d9.dir/objects.a
C:/MinGW/bin/ar.exe cr CMakeFiles/cmTC_394d9.dir/objects.a @CMakeFiles/cmTC_394d9.dir/objects1.rsp
E:/Yifan/Hiwi-FSD/FluCo1/Libraries/fsd-libs/trunk/nbproject/private/tools/localhost/MinGW/gcc.exe -Wl,–whole-archive CMakeFiles/cmTC_394d9.dir/objects.a -Wl,–no-whole-archive -o cmTC_394d9.exe -Wl,–out-implib,libcmTC_394d9.dll.a -Wl,–major-image-version,0,–minor-image-version,0 @CMakeFiles/cmTC_394d9.dir/linklibs.rsp
c:/mingw/bin/…/lib/gcc/mingw32/9.2.0/…/…/…/…/mingw32/bin/ld.exe: CMakeFiles/cmTC_394d9.dir/objects.a(src.c.obj):src.c:(.text+0x36): undefined reference to `_imp__pthread_create’

c:/mingw/bin/…/lib/gcc/mingw32/9.2.0/…/…/…/…/mingw32/bin/ld.exe: CMakeFiles/cmTC_394d9.dir/objects.a(src.c.obj):src.c:(.text+0x4c): undefined reference to `_imp__pthread_detach’

c:/mingw/bin/…/lib/gcc/mingw32/9.2.0/…/…/…/…/mingw32/bin/ld.exe: CMakeFiles/cmTC_394d9.dir/objects.a(src.c.obj):src.c:(.text+0x62): undefined reference to `_imp__pthread_cancel’

c:/mingw/bin/…/lib/gcc/mingw32/9.2.0/…/…/…/…/mingw32/bin/ld.exe: CMakeFiles/cmTC_394d9.dir/objects.a(src.c.obj):src.c:(.text+0x80): undefined reference to `_imp__pthread_join’

c:/mingw/bin/…/lib/gcc/mingw32/9.2.0/…/…/…/…/mingw32/bin/ld.exe: CMakeFiles/cmTC_394d9.dir/objects.a(src.c.obj):src.c:(.text+0x9e): undefined reference to `pthread_atfork’

c:/mingw/bin/…/lib/gcc/mingw32/9.2.0/…/…/…/…/mingw32/bin/ld.exe: CMakeFiles/cmTC_394d9.dir/objects.a(src.c.obj):src.c:(.text+0xaa): undefined reference to `_imp__pthread_exit’

collect2.exe: error: ld returned 1 exit status
make[1]: *** [cmTC_394d9.exe] Error 1
make[1]: Leaving directory `/e/Yifan/Hiwi-FSD/FluCo1/Libraries/fsd-libs/trunk/build-dev/CMakeFiles/CMakeTmp’
make: *** [cmTC_394d9/fast] Error 2

Source file was:
#include <pthread.h>

static void* test_func(void* data)
return data;

Cmake Gcc

int main(void)
pthread_t thread;
pthread_create(&thread, NULL, test_func, NULL);
pthread_join(thread, NULL);
pthread_atfork(NULL, NULL, NULL);

return 0;

And the terminal output is:

cd ‘E:YifanHiwi-FSDFluCo1Librariesfsd-libstrunkbuild-dev’
C:/Program Files/CMake/bin/cmake.exe -G Unix Makefiles -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=E:/Yifan/Hiwi-FSD/FluCo1/Libraries/fsd-libs/trunk/nbproject/private/tools/localhost/MinGW/gcc.exe -DCMAKE_CXX_COMPILER=E:/Yifan/Hiwi-FSD/FluCo1/Libraries/fsd-libs/trunk/nbproject/private/tools/localhost/MinGW/g++.exe -DCMAKE_C_FLAGS_DEBUG=-g3 -gdwarf-2 -DCMAKE_CXX_FLAGS_DEBUG=-g3 -gdwarf-2 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DPROJECT_SUFFIX=-dev …
– The C compiler identification is GNU 9.2.0
– The CXX compiler identification is GNU 9.2.0
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Check for working C compiler: E:/Yifan/Hiwi-FSD/FluCo1/Libraries/fsd-libs/trunk/nbproject/private/tools/localhost/MinGW/gcc.exe - skipped
– Detecting C compile features
– Detecting C compile features - done
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Check for working CXX compiler: E:/Yifan/Hiwi-FSD/FluCo1/Libraries/fsd-libs/trunk/nbproject/private/tools/localhost/MinGW/g++.exe - skipped
– Detecting CXX compile features
– Detecting CXX compile features - done
– The cmake will use build type Debug
– libfsd-io-dev version is 1.0+
– Install include dir include/fsd-io-dev
– fsd-io-dev PROJECT_SOURCE_DIR = E:/Yifan/Hiwi-FSD/FluCo1/Libraries/fsd-libs/trunk/IO
– fsd-io-dev Build directory = E:/Yifan/Hiwi-FSD/FluCo1/Libraries/fsd-libs/trunk/build-dev
– Found PkgConfig: C:/MinGW/bin/pkg-config.exe (found version “0.26”)
– Checking for one of the modules ‘openssl’
CMake Error at C:/Program Files/CMake/share/cmake-3.20/Modules/FindPkgConfig.cmake:843 (message):
None of the required ‘openssl’ found
Call Stack (most recent call first):
IO/CMakeLists.txt:47 (pkg_search_module)

– Looking for pthread.h
– Looking for pthread.h - found
– Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
– Check if compiler accepts -pthread
– Check if compiler accepts -pthread - yes
– Found Threads: TRUE
– libfsd-log-dev version is 1.0+
– fsd-log-dev PROJECT_SOURCE_DIR = E:/Yifan/Hiwi-FSD/FluCo1/Libraries/fsd-libs/trunk/Log
– fsd-log-dev Build directory = E:/Yifan/Hiwi-FSD/FluCo1/Libraries/fsd-libs/trunk/build-dev
– Install include dir include/fsd-log-dev
– libfsd-math-dev version is 1.0+
– fsd-math-dev PROJECT_SOURCE_DIR = E:/Yifan/Hiwi-FSD/FluCo1/Libraries/fsd-libs/trunk/Math
– fsd-math-dev Build directory = E:/Yifan/Hiwi-FSD/FluCo1/Libraries/fsd-libs/trunk/build-dev
– Configuring incomplete, errors occurred!
See also “E:/Yifan/Hiwi-FSD/FluCo1/Libraries/fsd-libs/trunk/build-dev/CMakeFiles/CMakeOutput.log”.
See also “E:/Yifan/Hiwi-FSD/FluCo1/Libraries/fsd-libs/trunk/build-dev/CMakeFiles/CMakeError.log”.

How To Make Gcc Makefile

PRE-BUILD FAILED (exit value 1, total time: 8s)

Cmake Use Gcc

Can anyone please help me about it? If you need any further information, I would be glad to offer. I have totally no idea about what’s the cause and where may I find it. I would really appreciate your help, thanksss!!