Working cmake/mingw configuration stopped working. The C compiler is not able to compile a simple test program - c

I write the C program using MinGW on windows 10 with Clion IDE. I had everything working and compiled successfully multiple times before. Can't link the error with any action but now cmake test in Clion fails - "Test Cmake run finished with errors" and I can't compile. Cmake error:
-- The C compiler identification is GNU 9.2.0
-- The CXX compiler identification is GNU 9.2.0
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe -- broken
CMake Error at C:/Users/karol/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/193.6015.37/bin/cmake/win/share/cmake-3.15/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"C:/msys64/mingw64/bin/gcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/karol/AppData/Local/Temp/cmake_check_environment/_build11621595605978509144/CMakeFiles/CMakeTmp
Run Build Command(s):C:/msys64/mingw64/bin/mingw32-make.exe cmTC_15aad/fast && C:/msys64/mingw64/bin/mingw32-make.exe -f CMakeFiles\cmTC_15aad.dir\build.make CMakeFiles/cmTC_15aad.dir/build
mingw32-make.exe[1]: Entering directory 'C:/Users/karol/AppData/Local/Temp/cmake_check_environment/_build11621595605978509144/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_15aad.dir/testCCompiler.c.obj
C:\msys64\mingw64\bin\gcc.exe -o CMakeFiles\cmTC_15aad.dir\testCCompiler.c.obj -c C:\Users\karol\AppData\Local\Temp\cmake_check_environment\_build11621595605978509144\CMakeFiles\CMakeTmp\testCCompiler.c
Linking C executable cmTC_15aad.exe
C:\Users\karol\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\193.6015.37\bin\cmake\win\bin\cmake.exe -E cmake_link_script CMakeFiles\cmTC_15aad.dir\link.txt --verbose=1
C:\Users\karol\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\193.6015.37\bin\cmake\win\bin\cmake.exe -E remove -f CMakeFiles\cmTC_15aad.dir/objects.a
C:\msys64\mingw64\bin\ar.exe cr CMakeFiles\cmTC_15aad.dir/objects.a #CMakeFiles\cmTC_15aad.dir\objects1.rsp
C:\msys64\mingw64\bin\gcc.exe -Wl,--whole-archive CMakeFiles\cmTC_15aad.dir/objects.a -Wl,--no-whole-archive -o cmTC_15aad.exe -Wl,--out-implib,libcmTC_15aad.dll.a -Wl,--major-image-version,0,--minor-image-version,0 #CMakeFiles\cmTC_15aad.dir\linklibs.rsp
gcc.exe: fatal error: cannot execute 'ld': CreateProcess: No such file or directory
compilation terminated.
mingw32-make.exe[1]: *** [CMakeFiles\cmTC_15aad.dir\build.make:88: cmTC_15aad.exe] Error 1
mingw32-make.exe[1]: Leaving directory 'C:/Users/karol/AppData/Local/Temp/cmake_check_environment/_build11621595605978509144/CMakeFiles/CMakeTmp'
mingw32-make.exe: *** [Makefile:120: cmTC_15aad/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:1 (project)
-- Configuring incomplete, errors occurred!
See also "C:/Users/karol/AppData/Local/Temp/cmake_check_environment/_build11621595605978509144/CMakeFiles/CMakeOutput.log".
See also "C:/Users/karol/AppData/Local/Temp/cmake_check_environment/_build11621595605978509144/CMakeFiles/CMakeError.log".
Error code: 1
I don't know what caused it. One thing I did around the time it broke is turn off avast cyber capture. But now I turned off avast antivirus completely and turned off "Check apps and files" option in Defender. The latter I did when Clion popped a notification saying "Windows Defender might be interrupting build speed". I also clicked "fix" in this Clion pop-up and it added project folders to exceptions. Clion notified me of it not immediately after the error but way later.
The directory "C:/Users/karol/AppData/Local/Temp/cmake_check_environment/" mentioned in the error report doesn't exist. I tried unchecking "read-only access" of AppData/Local/temp directory but Windows keeps putting it on. Between those changes and antivirus changes, I was restarting windows many times.
The error message i get when trying to compile:
C:\Users\karol\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\193.6015.37\bin\cmake\win\bin\cmake.exe --build C:\Users\karol\Desktop\studia\wstep_do_C\final_project\cmake-build-debug --target final_project -- -j 2
[ 20%] Linking C executable final_project.exe
gcc.exe: fatal error: cannot execute 'ld': CreateProcess: No such file or directory
compilation terminated.
mingw32-make.exe[3]: *** [CMakeFiles\final_project.dir\build.make:134: final_project.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:75: CMakeFiles/final_project.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:82: CMakeFiles/final_project.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: final_project] Error 2
Many poeple experienced simmilar error caused by non-latin characters in path, not the case here. Also i don't suspect mingw installation as it used to work.
Clion toolchains settings

Related

CLion erroring on compiling - call stack problem

I'm trying to compile a hello world file in clion but I keep getting this error
"C:\Program Files\JetBrains\CLion 2018.3.1\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\NAME\CLionProjects\HelloWorld
CMake Error at C:/Program Files/JetBrains/CLion 2018.3.1/bin/cmake/win/share/cmake-3.13/Modules/CMakeDetermineCompilerId.cmake:523 (file):
file STRINGS file
"C:/Users/NAME/CLionProjects/HelloWorld/cmake-build-debug/CMakeFiles/3.13.1/CompilerIdC/a.exe"
cannot be read.
How do I get rid of it?
Image of tooltip section
EDIT:
I keep getting the following compile error:
====================[ Build | HelloWorld | Debug ]==============================
"C:\Program Files\JetBrains\CLion 2018.3.1\bin\cmake\win\bin\cmake.exe" --build C:\Users\ssez\CLionProjects\HelloWorld\cmake-build-debug --target HelloWorld -- -j 4
[ 33%] Linking C executable HelloWorld.exe
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot open output file HelloWorld.exe: Permission denied
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: * [HelloWorld.exe] Error 1
CMakeFiles\HelloWorld.dir\build.make:99: recipe for target 'HelloWorld.exe' failed
mingw32-make.exe[2]: [CMakeFiles/HelloWorld.dir/all] Error 2
CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/HelloWorld.dir/all' failed
mingw32-make.exe1: [CMakeFiles/HelloWorld.dir/rule] Error 2
CMakeFiles\Makefile2:83: recipe for target 'CMakeFiles/HelloWorld.dir/rule' failed
mingw32-make.exe: * [HelloWorld] Error 2
Makefile:117: recipe for target 'HelloWorld' failed
Did you setup the toolchain in CLion after you installed both MinGW and CLion?
File > Settings > Build, Execution, Deployment > Toolchains
CLion can normally autodetect the compilers that it knows about, however I believe that it still has to be told which compiler to look for at first.

What does this linking error mean when installing portmidi?

After I configured the cmake file for portmidi, and proceeded to use make to make the necessary files, I encountered this error during compilation:
- Build files have been written to: /home/mycomputername
/Desktop/portmedia/portmidi
[ 2%] Linking C shared library /Release/libpmjni.so
/usr/bin/x86_64-linux-gnu-ld: cannot open output file /Release/libpmjni.so: No such file or directory
collect2: error: ld returned 1 exit status
pm_common/CMakeFiles/pmjni.dir/build.make:251: recipe for target '/Release/libpmjni.so' failed
make[2]: *** [/Release/libpmjni.so] Error 1
CMakeFiles/Makefile2:87: recipe for target 'pm_common/CMakeFiles/pmjni.dir/all' failed
make[1]: *** [pm_common/CMakeFiles/pmjni.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2
I'm quite confused. I've tried to insert the flags -fpic in the cxx-flags section of ccmake and change the default java install paths to no avail. Quite frankly, I think it has to do with the messing up of execution order, but I don't know where.
Any help will be greatly appreciated.
Apparently, there was some configuring to do in the directories that CMake points to in ccmake configuration. I just redownloaded the files and unzipped it into a newly made portmedia directory. Also, to make sure that you don't get any hiccups in making pm_defaults, refer to Nate's answer. To quote:
Apparently, one of the Makefiles generated by ccmake is broken. I was able to fix the issue by running
sed -i 's/pm_java\/pm_java/pm_java/' build.make
in the pm_java/CMakeFiles/pmdefaults_target.dir/ subdirectory of the
project after running ccmake . (on Ubuntu, though). (The sed
command replaces all occurrences of pm_java/pm_java by pm_java.)
Everything compiles, and I can even run pmdefaults from the
Release directory using
java -Djava.library.path=. -jar pmdefaults.jar

Failed to build C code by using generated NDK toolchain

I am working on build a c library for android 5.1.1.
First I build a standalone toolchain by following the google ndk standalone toolchain guild.
<prebuilt_ndk_r12b_path>/build/tools/make-standalone-toolchain.sh --platform=android-22 --ndk-dir=<prebuilt_ndk_r12b_path> --install-dir=/home/r0ng/utilities/ndk --toolchain=x86_64-linux-android-4.9
After that, I exported CC, AR and RANLIB in ~/.bashrc
export ANDROID_NDK=/home/r0ng/utilities/ndk
SYSROOT=$ANDROID_NDK/sysroot
export CC="$ANDROID_NDK/bin/arm-linux-androideabi-gcc-4.9.x --sysroot=$SYSROOT"
export AR="$ANDROID_NDK/bin/arm-linux-androideabi-gcc-ar --sysroot=$SYSROOT"
export RANLIB="$ANDROID_NDK/bin/arm-linux-androideabi-gcc-ranlib --sysroot=$SYSROOT"
But when I tried to compile by using cmake ... I had the following errors:
-- The C compiler identification is GNU 4.9.0
-- The CXX compiler identification is GNU 4.9.3
-- Check for working C compiler: /home/r0ng/utilities/ndk/bin/arm-linux-androideabi-gcc
-- Check for working C compiler: /home/r0ng/utilities/ndk/bin/arm-linux-androideabi-gcc -- broken
CMake Error at /usr/share/cmake-3.5/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "/home/r0ng/utilities/ndk/bin/arm-linux-androideabi-gcc" is
not able to compile a simple test program.
It fails with the following output:
Change Dir: /home/r0ng/projects/relic/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_8d7ca/fast"
/usr/bin/make -f CMakeFiles/cmTC_8d7ca.dir/build.make
CMakeFiles/cmTC_8d7ca.dir/build
make[1]: Entering directory
'/home/r0ng/projects/relic/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_8d7ca.dir/testCCompiler.c.o
/home/r0ng/utilities/ndk/bin/arm-linux-androideabi-gcc
--sysroot=/home/r0ng/utilities/ndk -o
CMakeFiles/cmTC_8d7ca.dir/testCCompiler.c.o -c
/home/r0ng/projects/relic/build/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_8d7ca
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_8d7ca.dir/link.txt
--verbose=1
/home/r0ng/utilities/ndk/bin/arm-linux-androideabi-gcc
--sysroot=/home/r0ng/utilities/ndk
CMakeFiles/cmTC_8d7ca.dir/testCCompiler.c.o -o cmTC_8d7ca -rdynamic
/home/r0ng/utilities/ndk/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld:
error: cannot open crtbegin_dynamic.o: No such file or directory
/home/r0ng/utilities/ndk/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld:
error: cannot open crtend_android.o: No such file or directory
/home/r0ng/utilities/ndk/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld:
error: cannot find -lc
/home/r0ng/utilities/ndk/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld:
error: cannot find -ldl
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_8d7ca.dir/build.make:97: recipe for target 'cmTC_8d7ca'
failed
make[1]: *** [cmTC_8d7ca] Error 1
make[1]: Leaving directory
'/home/r0ng/projects/relic/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_8d7ca/fast' failed
make: *** [cmTC_8d7ca/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:6 (project)
-- Configuring incomplete, errors occurred!
See also "/home/r0ng/projects/relic/build/CMakeFiles/CMakeOutput.log".
See also "/home/r0ng/projects/relic/build/CMakeFiles/CMakeError.log".
It seems that the compiler is unable to find "crtbegin_dynamic.o", "crtend_android.o", "libc" neither "libdl". But when I checked, those files are all in the folder $HOME/utilities/ndk/sysroot/usr/lib. And I already set the --sysroot in CC, AR and RANLIB.
Update 1 :
After changed the toolchain generation command based on Dan Albert's comment, The command cmake .. is able to be run successfully. But when I run make . I got following error:
arm-linux-androideabi-gcc-4.9.x: error: unrecognized command line option '-m64'
src/CMakeFiles/relic.dir/build.make:62: recipe for target 'src/CMakeFiles/relic.dir/relic_err.c.o' failed
make[2]: *** [src/CMakeFiles/relic.dir/relic_err.c.o] Error 1
CMakeFiles/Makefile2:120: recipe for target 'src/CMakeFiles/relic.dir/all' failed
make[1]: *** [src/CMakeFiles/relic.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Thanks,
Environment:
OS: Ubuntu 16.04 LTS
gcc / g++: 4.9.3
AOSP: 5.1.1_r30
NDK: android-ndk-r12b
cmake: 3.5.1
If you want to use cmake, you don't need a standalone toolchain. Android Studio natively supports cmake now: http://tools.android.com/tech-docs/external-c-builds
NDK r13 (not released yet) will also ship a cmake toolchain file for using cmake directly (the method shown in https://stackoverflow.com/a/5099229/632035).
You shouldn't add --sysroot= explicitly. Standalone toolchain already knows about proper one.

Using CMake with AVR Toolchain in Cygwin or MinGW

I'm currently trying to get a toolchain setup so I can build an AVR project from CLion.
My starting point is this, specifically, the Blink example. The issue is that it, along with existing CMake for AVR examples, are all for Linux based systems.
What I've tried is installing WinAVR to get the executables. I've modified the CMakeList.txt so the program names contain the following:
set(AVRCPP "C:/WinAVR-20100110/bin/avr-g++")
set(AVRC "C:/WinAVR-20100110/bin/avr-gcc")
set(AVRSTRIP "C:/WinAVR-20100110/bin/avr-strip")
set(OBJCOPY "C:/WinAVR-20100110/bin/avr-objcopy")
set(OBJDUMP "C:/WinAVR-20100110/bin/avr-objdump")
set(AVRSIZE "C:/WinAVR-20100110/bin/avr-size")
set(AVRDUDE "C:/WinAVR-20100110/bin/avrdude")
set(AVRAS "C:/WinAVR-20100110/bin/avr-as")
While using the Cygwin environment, CMake has no issue finding my compilers, but when I try to build the project, avr-gcc is being passed parameters in Linux format.
C:/WinAVR-20100110/bin/avr-gcc.exe -o CMakeFiles/cmTryCompileExec420260872.dir/testCCompiler.c.obj -c /cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp/testCCompiler.c
avr-gcc.exe: /cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp/testCCompiler.c: No such file or directory
Is there a way to have CMake pass avr-gcc arguments in a format it can work with?
For reference, this is the full output:
Error:The C compiler "C:/WinAVR-20100110/bin/avr-gcc" is not able to compile a simple test program.
It fails with the following output:
Change Dir: /cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp
Run Build Command:/usr/bin/make.exe "cmTryCompileExec420260872/fast"
/usr/bin/make -f CMakeFiles/cmTryCompileExec420260872.dir/build.make CMakeFiles/cmTryCompileExec420260872.dir/build
make[1]: Entering directory '/cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp'
/usr/bin/cmake.exe -E cmake_progress_report /cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec420260872.dir/testCCompiler.c.obj
C:/WinAVR-20100110/bin/avr-gcc.exe -o CMakeFiles/cmTryCompileExec420260872.dir/testCCompiler.c.obj -c /cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp/testCCompiler.c
avr-gcc.exe: /cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp/testCCompiler.c: No such file or directory
avr-gcc.exe: no input files
CMakeFiles/cmTryCompileExec420260872.dir/build.make:60: recipe for target 'CMakeFiles/cmTryCompileExec420260872.dir/testCCompiler.c.obj' failed
make[1]: Leaving directory '/cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp'
make[1]: *** [CMakeFiles/cmTryCompileExec420260872.dir/testCCompiler.c.obj] Error 1
Makefile:117: recipe for target 'cmTryCompileExec420260872/fast' failed
make: *** [cmTryCompileExec420260872/fast] Error 2
CMake will not be able to correctly generate this project.
I use cmake and avr on windows and on linux.
The syntax is the same. Why do you want to use cygwin in the mid of that?
In any case you didn't show your toolchain file.
When cross compiling using cmake you need to provide a toolchain file where you set all the configuration related to the compiler.
You need to do this because when cmake starts it try to compile a simple program and it try to run it. If you are using an avr compiler on a computer cmake can't run the executable, so it fails.
You need to put an extra care including this command in the toolchain:
SET(CMAKE_SYSTEM_NAME Generic)
it is needed for skip this compilation and so to avoid the failure.
I think this is a good read where to begin:
http://playground.arduino.cc/Code/CmakeBuild

Openssl (OS X Yosemite) Installation Make Errors

While OpenSSL ver. 0.9.8za was already installed on my system (darwin64-x86_64-cc), I elected to install the latest version, 1.0.1j, using the instructions for UNIX systems, in the "INSTALL" file within the downloaded tarball. I chose to configure with the 64-bit option, './Configure darwin64-x86_64-cc', and then ran the makefile. So far, so good. After about a minute, as I was thinking the installation would be successful, the compiler displayed following error messages, after compilation terminated:
Compile command line: './Configure darwin64-x86_64-cc' (Openssl suggestion for 64-bit)
duplicate symbol _OPENSSL_cleanse in:
../libcrypto.a(mem_clr.o)
../libcrypto.a(x86_64cpuid.o)
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [link_app.] Error 1
make[1]: *** [openssl] Error 2
make: *** [build_apps] Error 1
The problem appears to originate in the linker, but then again, I'm still a command line novice.
So, given this error, what needs to be changed in order to fully compile OpenSSL 1.0.1j?
When the automatic configuration route was taken (./config), the following error is given:
cc -I.. -I../.. -I../modes -I../asn1 -I../evp -I../../include -DOPENSSL_THREADS -D_REENTRANT
DDSO_DLFCN -DHAVE_DLFCN_H -arch i386 -O3 -fomit-frame-pointer -DL_ENDIAN
DOPENSSL_BN_ASM_PART_WORDS -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_GF2m
DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DRMD160_ASM -DAES_ASM -DVPAES_ASM -DWHIRLPOOL_ASM
DGHASH_ASM -c -o obj_xref.o obj_xref.c
ar r ../../libcrypto.a o_names.o obj_dat.o obj_lib.o obj_err.o obj_xref.o
ar: ../../libcrypto.a is a fat file (use libtool(1) or lipo(1) and ar(1) on it)
ar: ../../libcrypto.a: Inappropriate file type or format
make[2]: *** [lib] Error 1
make[1]: *** [subdirs] Error 1
make: *** [build_crypto] Error 1
Update: The "PROBLEMS" documentation suggests changing two lines in the apps/Makefile and test/Makefile:
"LIBCRYPTO= -L.. -lcrypto"
"LIBSSL=-L -lssl"
to:
"LIBCRYPTO=../libcrypto.a"
"LIBSSL=../libssl.a"
Re-attempting make afterward, the same message was given.
My sincere thanks for the help and comments by jww, Jonathan L. and others gave/made. Should errors persist, I'll continue the search for the missing information and eventually post a solution.
I'm not sure what your problem is. Using XCode 6 (6.1.1, I believe) on Yosemite 10.10.1, I was able to get openssl-1.0.1j from OpenSSL.org and extract it. I then configured it with:
./Configure --prefix=/usr/openssl/openssl-1.0.1j darwin64-x86_64-cc zlib threads shared
With those, I was able to build, test and install without problem. That's pretty close to what you did; I simply have noted the presence of zlib (compression) and requested thread and shared library support — and specified a slightly out-of-the-way location to install it. (The top-level directory specified with --prefix existed but was empty.) I tried adding sctp to the configuration options, but no dice — an SCTP header is missing, so I didn't bother to try further.

Resources