简体   繁体   English

如何在 Cygwin 中更改 C++ 编译器?

[英]How to change the C++ compiler in Cygwin?

I am using windows, and I need to compile a cpp file.我用的是windows,需要编译一个cpp文件。 I am using Cygwin to run the command sh .我正在使用 Cygwin 运行命令sh I have already MinGw installed.我已经安装了 MinGw。 The problem is that when I run the command, I find that Cygwin is calling the compiler of MinGw.问题是当我运行命令时,我发现 Cygwin 正在调用 MinGw 的编译器。 Here is a trace of the error i get:这是我得到的错误的痕迹:

 $ sh build_cpp.sh
mkdir: cannot create directory ‘build’: File exists
-- The CXX compiler identification is GNU 7.2.0
-- Check for working CXX compiler: /cygdrive/c/MinGW-124/MinGW-CPTR-124/bin/g++.exe
-- Check for working CXX compiler: /cygdrive/c/MinGW-124/MinGW-CPTR-124/bin/g++.exe -- broken
CMake Error at /usr/share/cmake-3.14.5/Modules/CMakeTestCXXCompiler.cmake:53 (message):
  The C++ compiler

    "/cygdrive/c/MinGW-124/MinGW-CPTR-124/bin/g++.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /cygdrive/c/users/user/PycharmProjects/crnn-master/src/cpp/build/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/bin/make.exe cmTC_71c00/fast
    /usr/bin/make -f CMakeFiles/cmTC_71c00.dir/build.make CMakeFiles/cmTC_71c00.dir/build
    make[1]: Entering directory '/cygdrive/c/users/user/PycharmProjects/crnn-master/src/cpp/build/CMakeFiles/CMakeTmp'
    Building CXX object CMakeFiles/cmTC_71c00.dir/testCXXCompiler.cxx.o
    /cygdrive/c/MinGW-124/MinGW-CPTR-124/bin/g++.exe     -o CMakeFiles/cmTC_71c00.dir/testCXXCompiler.cxx.o -c /cygdrive/c/users/user/PycharmProjects/crnn-master/src/cpp/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
    g++.exe: error: /cygdrive/c/users/user/PycharmProjects/crnn-master/src/cpp/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx: No such file or directory
    g++.exe: fatal error: no input files
    compilation terminated.
    make[1]: *** [CMakeFiles/cmTC_71c00.dir/build.make:66: CMakeFiles/cmTC_71c00.dir/testCXXCompiler.cxx.o] Error 1
    make[1]: Leaving directory '/cygdrive/c/users/user/PycharmProjects/crnn-master/src/cpp/build/CMakeFiles/CMakeTmp'
    make: *** [Makefile:121: cmTC_71c00/fast] Error 2




  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:3 (PROJECT)


-- Configuring incomplete, errors occurred!
See also "/cygdrive/c/users/user/PycharmProjects/crnn-master/src/cpp/build/CMakeFiles/CMakeOutput.log".
See also "/cygdrive/c/users/user/PycharmProjects/crnn-master/src/cpp/build/CMakeFiles/CMakeError.log".
make: *** No targets specified and no makefile found.  Stop.
cp: cannot stat '*.so': No such file or directory

I tried changing the variables of environment, installing devel package and changing the cache variables (CMAKE_CXX_COMPILER, CMAKE_CC_COMPILER) with the command cmake -d .我尝试更改环境变量,安装 devel package 并使用命令cmake -d更改缓存变量(CMAKE_CXX_COMPILER,CMAKE_CC_COMPILER)。 Where can I change the compiler of Cygwin so it will uses its compiler?我在哪里可以更改 Cygwin 的编译器以便它使用它的编译器?

I might be due to your Windows path variable.我可能是由于您的 Windows 路径变量。 If you have multiple binaries named g++ including one from mingw, you should add the correct one to your environment variable and remove the others.如果您有多个名为 g++ 的二进制文件,其中一个来自 mingw,则应将正确的一个添加到您的环境变量中并删除其他的。 Also make use of the command which g++ to know which binary would be used.还可以使用命令which g++来了解将使用哪个二进制文件。 You can also maybe provide the full path of the right compiler as a workaround.您也可以提供正确编译器的完整路径作为解决方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM