I'm trying to set up CMake for a project I'm working on, and I'm first trying to compile a simple Hello World program in C. I'm using Windows 10 with MSYS2. If I invoke the compiler (GCC) directly in Bash, it compiles fine without warnings or errors and gives an executable as output which prints "Hello, world!" exactly as expected. My problem comes in when I try to use CMake to compile my project. When I run cmake -G Ninja .. to compile my project, it throws this error:
CMake Error at C:/msys64/mingw64/share/cmake-3.15/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"C:/msys64/mingw64/bin/cc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/dylanweber/Documents/C-Projects/webapp/build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/msys64/usr/bin/ninja.exe cmTC_45340 && [1/2] Building C object CMakeFiles/cmTC_45340.dir/testCCompiler.c.obj
FAILED: CMakeFiles/cmTC_45340.dir/testCCompiler.c.obj
C:\msys64\mingw64\bin\cc.exe -o CMakeFiles/cmTC_45340.dir/testCCompiler.c.obj -c testCCompiler.c
/bin/sh: C:msys64mingw64bincc.exe: command not found
ninja: build stopped: subcommand failed.
Notice how it mentions C:msys64mingw64bingcc.exe... there must be some kind of path delineation problem but I've tried setting the CC environmental variable to C:\\msys64\\mingw64\\bin\\gcc.exe and C:/msys64/mingw64/bin/gcc.exe. I have been clearing the CMake caches between runs.
Here is my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.15)
project(webapp)
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
file(GLOB SOURCES "main/*.c")
add_executable(webapp ${SOURCES})
My code is in a "main" folder which is currently just one "main.c" file, in addition to a build directory used to keep all the temporary files in. The most frustrating part is that CMake was just working an hour ago, and I didn't change anything. What can I do to fix this problem?
The solution was not only installing the MinGW64 version of CMake, but also the MinGW64 version of Ninja as well. Since they have different pathing schemes compared to MSYS, they didn't play well together until they were both on the same POSIX-like platform.
Related
I’ve recently done a git clone of the wine repository at https://github.com/wine-mirror/wine and downloaded the folders to (~/repo/wine/). I'm trying to run Notepad, but don't know how. I am assuming that to build and compile it, I would need to run main.c from the notepad folder. I’m running GCC v 8.3.0 on Raspbian/Linux 10
With the repo downloaded as shown above, what build commands would I need to run notepad’s main.c from Geanie (or any, currently using Geanie) IDE? Can a single compile and/or build command let me run notepad from Geanie, or am I missing something?
Other details (not needed if what I thought I was going to do can't be done):
I wanted to try to run main.c at (~/repo/wine/programs/main.c), but don’t know how to get GCC to view all of the necessary header files. In my execution instructions window in Geanie, I have
gcc -Wall -c “%f” /home/pi/repo/wine/include
and my build instruction (it won't compile, so this isn't anything I've even gotten to work with yet...)
gcc -Wall -o “%e” “%f” /home/pi/repo/wine/include
When I attempt to compile, I get:
Stdio.h:11:10: fatal error: corecrt_wstdui.h: No such file or directory.
#include <corecrt_wstudio.h>
I went over to the stdio.h and attempted to add a build instruction here as well that also targets the include folder (which is the supposedly missing file), but it won’t compile.
Using cpp -v, I can see my include paths for GCC are as follows:
#include”...” paths:
#include<...> paths:
\usr\lib\gcc\arm-linux-gnueabihf\8\include
\usr\local\include
\usr\lib\gcc\arm-linux-gnueabihf\8\include-fixed
\usr\include\arm-linux-gnueabihf
\usr\include
I have written a project that compiles with CMake. Now I am trying to get emscripten to compile it, but I am getting an error. Beginning in the root of the Cmake project, the steps I take are as follows:
$mkdir build_emscripten
$cd build_emscripten
$emcmake cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo
$sudo make
Everything works up until the command make. What happens is it links the C executable successfully then it gives the error "ERROR:root:/usr/include/python2.7: Input file has an unknown suffix, don't know what to do with it!"
Then it proceeds to give multiple other errors causes by this. What can I do to fix this?
I have the MinGW install previously working fine with MSYS. They are installed properly and functioning just well.
I installed the PortAudio library and did the install and got the success message after:
./configure
make
make install
When I try to compile samples:
c:\c>gcc patest_mono.c -o pa.exe
patest_mono.c:50:23: fatal error: portaudio.h: No such file or directory
#include "portaudio.h"
^
compilation terminated.
I'm new. I have a feeling I might be doing something fundamentally wrong with the way I'm trying to create the exe from compiling. It's been somewhat of a puzzle quest so far, but I've tried to figure it out and think I am close but completely missing something.
PATH variable ?
In the PortAudio MinGW build instructions I noticed
"The above should create a working version though you might want to
provide '–prefix=<path-to-install-dir>' to configure. "
I've tried adding C:\MingW\PortAudio into the user path. Doesn't work.
I've also tried running the commands in Bash and they come back with an error message "No Rule to make target 'paexpink'" either with the make command, and with gcc .c -o .exe I just get the same error message as compiling straight from the cmd prompt.
I found another source on stack overflow thread with no answers, but the user had commented that http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio provided them a solution but I tried installing the 5 cpython binaries and under the assumption I did it right, it didn't work either.
Thanks for your help,
Julian
To build and install portaudio, you need to add -prefix=/c/<"path to base of the MinGW directory"> to the ./configure line.
For example: ./configure -prefix=/c/MinGW/
then continue the installation by doing
make
After that, do the
make install
and that should install the portaudio files into MinGW.
After it has finished installing, you need to add -lportaudio to the compile command whenever you compile any programs that you want to use PortAudio in.
For example: gcc -o test test.c -lportaudio
I just figured out how to do this today, so I may have accidentally forgotten a few steps.
I am trying to install and run cmocka library for unit testing on Mac OSX Yosemite 10.10.3, but I've got some problems with the RPATH settings.
Update:
Thanks to #baf, I was able to include cmocka.h in my CMakeLists.txt manually like this:
set(CMAKE_C_FLAGS_DEBUG "-I/usr/local/include/cmocka.h")
However, why is it so that I have to do it manually?
I've already tried many different ways of installing it:
What I've done so far:
Download cmocka from here: here. Version 1.0.
tar xvf cmocka-1.0.1.tar.xz
cd cmocka-1.0.1, mkdir build and cd build
sudo cmake ..
I get a message like this here:
-- Configuring done
CMake Warning (dev):
Policy CMP0042 is not set: MACOSX_RPATH is enabled by default. Run "cmake --help-policy CMP0042" for policy details. Use the cmake_policy command to set the policy and suppress this warning.
MACOSX_RPATH is not specified for the following targets:
cmocka_shared
This warning is for project developers. Use -Wno-dev to suppress it.
Question #1: How can I set the rpath so that there is no warning like the one above?
sudo make
sudo make install
cmocka should be installed now, right?
Running cmake for my program which is using cmocka library.
So now I run cmake for my program and my main CMakeList.txt file has lines like this:
find_library (CMOCKA cmocka)
if (NOT CMOCKA)
message (WARNING "Cmocka library not found.")
endif (NOT CMOCKA)
But the warning doesn't show up during this phase, so I believe that find_libarary(CMOCKA cmocka) has successfully located cmocka on my computer.
Running make for my program.
While running make I get an error like this:
fatal error:<br>
'cmocka.h' file not found<br>
#include <cmocka.h>
^
1 error generated.
So I guess that cmocka cannot be found...
Question #2: Why cmocka library cannot be found?
Additional notes:
I've tried running
$ export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
but it didn't helped. I guess it is a solution for Linux, not Mac.
I've tried to learn something about RAPTH on Mac in cmake from their official documentation here: http://www.cmake.org/Wiki/CMake_RPATH_handling. However I understood very little and I wasn't able to come up with a solution for my problem.
I've tried installing cmocka using brew but I got the same result.
Moreover, I've read many questions at SO about RPATH, linking and cmocka, but I couldn't find a suitable solution as well. Nevertheless, here is the list of related threads:
How to set the runtime path (-rpath) of an executable with gcc under Mac OSX?
https://stackoverflow.com/questions/29721183/getting-undefined-symbols-for-architecture-x86-64-when-trying-to-build-on-osx
How to configure scons to link using rpath on mac?
mariadb install failure: make (Mac OSX 10.6.8)
I've run otool -L cmocka. Here's what I got:
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool: can't open file: cmocka (No such file or directory)
I was able to successfully compile my program (thanks to baf) when I added the -I/usr/local/include flag to my debug flags:
set(CMAKE_C_FLAGS_DEBUG "-std=gnu99 -Wall -pedantic -g -I/usr/local/include/cmocka.h")
I installed Eclipse in fedora and then installed the CDT plugin for developping C/C++ applications . All the installation are done !
So now i can create a C/C++ project but when it comes to running it i got this message
launch failed , Binary not found
and
unable to find full path to gcc.
gcc -O2 -g -Wall -c -fmessage-length=0 -o Rad1.o ../Rad1.c
Internal Builder: Cannot run program "gcc": Unknown reason
Error: Program "gcc" is not found in PATH
Is there any more configuration i must do so C/C++ runs?
Thanks.
Executing c/c++ program with eclipse+unix base plate-forme, it requied object file of the program to execute/run it. So first of all you need to build your program by just pressing Ctr+b to buid it. This will create an object file that was required. Now you enabled to run/execute your programe. Good luck :)