Netbeans error in c :make.exe error :build/Debug/MinGW-Windows/my-project-error.o - c

i am writing the following code in my netbeans sdk :
int main() {
printf("Hello World");
return 0;
}
and it gives me the following error :
make.exe[2]: *** [build/Debug/MinGW-Windows/fourier-transform.o] Error 1
make.exe[2]: Leaving directory
`/c/Users/As-/Documents/NetBeansProjects/CppApplication_1'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory
`/c/Users/As-/Documents/NetBeansProjects/CppApplication_1'
make.exe": *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 59s)
Any help in why is this error ?

Related

How to add Compiler Flag in CMakeLists Clion for shm_open [duplicate]

This question already has answers here:
undefined reference to `shm_open' using CMake
(2 answers)
Closed 1 year ago.
Simple Program:
#include <stdlib.h>
#include <sys/mman.h>
#include <fcntl.h>
int main() {
int shm_fd;
shm_fd=shm_open("sh",O_CREAT|O_RDWR,0666);
return 0;
}
The error is:
Warnung: undefined reference to »shm_open«
collect2: error: ld returned 1 exit status
CMakeFiles/Share_Memory_Project.dir/build.make:102: recipe for target 'Share_Memory_Project' failed
make[3]: *** [Share_Memory_Project] Error 1
CMakeFiles/Makefile2:94: recipe for target 'CMakeFiles/Share_Memory_Project.dir/all' failed
make[2]: *** [CMakeFiles/Share_Memory_Project.dir/all] Error 2
CMakeFiles/Makefile2:101: recipe for target 'CMakeFiles/Share_Memory_Project.dir/rule' failed
make[1]: *** [CMakeFiles/Share_Memory_Project.dir/rule] Error 2
Makefile:137: recipe for target 'Share_Memory_Project' failed
make: *** [Share_Memory_Project] Error 2
To fix this Problem, I have to add a Compiler Flag:
-lrt at the end. Like this: gcc main.c -o main -lrt. So When I put this in Command Line at Ubuntu Terminal it compile fine.
My Question is: How to add this Flag at my CMakeLists.txt in Clion?
How my file currently looks:
cmake_minimum_required(VERSION 3.19)
project(Share_Memory_Project C)
set(CMAKE_C_STANDARD 99)
add_executable(Share_Memory_Project main.c)
To link a target with a library, use target_link_libraries. You would:
add_executable(Share_Memory_Project main.c)
target_link_libraries(Share_Memory_Project PUBLIC rt)

undefined reference to `sqrt', 'log', [duplicate]

This question already has answers here:
Why do you have to link the math library in C?
(14 answers)
Closed 3 years ago.
When I compile this code:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main() {
char str[] = "3.6";
double res = atof(str);
printf("%f\n", sqrt(res));
return 0;
}
I get this error:
====================[ Build | untitled12 | Debug ]==============================
/snap/clion/81/bin/cmake/linux/bin/cmake --build /home/abdo/CLionProjects/untitled12/cmake-build-debug --target untitled12 -- -j 4
[ 50%] Linking C executable untitled12
/usr/bin/ld: CMakeFiles/untitled12.dir/main.c.o: in function `main':
/home/abdo/CLionProjects/untitled12/main.c:11: undefined reference to `sqrt'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/untitled12.dir/build.make:84: untitled12] Error 1
make[2]: *** [CMakeFiles/Makefile2:73: CMakeFiles/untitled12.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/untitled12.dir/rule] Error 2
make: *** [Makefile:118: untitled12] Error 2
I get same error when I replace 'sqrt' with 'log' or 'ln' ...
compiler: cc (Ubuntu 8.3.0-6ubuntu1) 8.3.0
The math library must be linked in when compiling. Add the -lm flag to your gcc command, after the source or object file(s).

call rrd_create from c file

I'm trying call rrd func from my project in CLion (on ubuntu), rrd.h is in /usr/include/.
My code:
#include <stdio.h>
#include <rrd.h>
int main() {
size_t argc = 6;
char *argv[] = {
"test.rrd",
"--start",
"920804400",
"DS:speed:COUNTER:600:U:U",
"RRA:AVERAGE:0.5:1:24",
"RRA:AVERAGE:0.5:6:10"
};
rrd_create(argc, argv);
return 0;
}
CMakeLists.txt:
cmake_minimum_required(VERSION 3.8)
project(rddtool)
set(CMAKE_C_STANDARD 11)
set(SOURCE_FILES main.c /usr/include/rrd.h)
add_executable(rddtool ${SOURCE_FILES})
Messages Build:
Scanning dependencies of target rddtool
[ 50%] Building C object CMakeFiles/rddtool.dir/main.c.o
[100%] Linking C executable rddtool
CMakeFiles/rddtool.dir/main.c.o: In function `main':
/home/parallels/CLionProjects/rddtool/main.c:14: undefined reference to `rrd_create'
collect2: error: ld returned 1 exit status
CMakeFiles/rddtool.dir/build.make:94: recipe for target 'rddtool' failed
make[3]: *** [rddtool] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/rddtool.dir/all' failed
make[2]: *** [CMakeFiles/rddtool.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/rddtool.dir/rule' failed
make[1]: *** [CMakeFiles/rddtool.dir/rule] Error 2
Makefile:118: recipe for target 'rddtool' failed
make: *** [rddtool] Error 2
How should I call rrd_create?
In CMakeLists.txt:
cmake_minimum_required(VERSION 3.8)
project(rddtool)
set(CMAKE_C_STANDARD 11)
set(SOURCE_FILES main.c)
find_library(RRD_LIBRARY librrd.so HINTS /usr/lib/x86_64-linux-gnu)
add_executable(rddtool ${SOURCE_FILES})
target_link_libraries(rddtool PUBLIC ${RRD_LIBRARY})

Netbeans Error when running a simple c program

If I manually compile the code below, I got no error:
/*
* File: newmain.c
* Author: Mike
*
* Created on September 18, 2015, 7:36 PM
*/
#include <stdio.h>
#include <stdlib.h>
/*
*
*/
int main(int argc, char** argv) {
printf ("Hello!");
return 0;
}
However, by doing the with NetBeans, I got the following error:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/c/Users/Mike/Documents/NetBeansProjects/CppApplication_1'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin_4.x-Windows/cppapplication_1.exe
make[2]: Entering directory '/cygdrive/c/Users/Mike/Documents/NetBeansProjects/CppApplication_1'
mkdir -p build/Debug/Cygwin_4.x-Windows
rm -f "build/Debug/Cygwin_4.x-Windows/newmain.o.d"
gcc -c -g -MMD -MP -MF "build/Debug/Cygwin_4.x-Windows/newmain.o.d" -o build/Debug/Cygwin_4.x-Windows/newmain.o newmain.c
mkdir -p dist/Debug/Cygwin_4.x-Windows
g++ -o dist/Debug/Cygwin_4.x-Windows/cppapplication_1 build/Debug/Cygwin_4.x-Windows/main.o build/Debug/Cygwin_4.x-Windows/newmain.o
build/Debug/Cygwin_4.x-Windows/newmain.o: In function `main':
/cygdrive/c/Users/Mike/Documents/NetBeansProjects/CppApplication_1/newmain.c:14: multiple definition of `main'
build/Debug/Cygwin_4.x-Windows/main.o:/cygdrive/c/Users/Mike/Documents/NetBeansProjects/CppApplication_1/main.cpp:15: first defined here
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:63: recipe for target 'dist/Debug/Cygwin_4.x-Windows/cppapplication_1.exe' failed
make[2]: *** [dist/Debug/Cygwin_4.x-Windows/cppapplication_1.exe] Error 1
make[2]: Leaving directory '/cygdrive/c/Users/Mike/Documents/NetBeansProjects/CppApplication_1'
nbproject/Makefile-Debug.mk:60: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/cygdrive/c/Users/Mike/Documents/NetBeansProjects/CppApplication_1'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
How can I get this code being executed in the NetBeans too?

What is wrong With make?

C
#include <linux/module.h>
#include <linux/kernel.h>
int init_module(void)
{
printk(KERN_INFO "Hello world 1.\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 1.\n");
}
/* makefile */
/* uname -r = 2.6.32-5-686 */
obj-m += hello.o
all :
make -C /lib/modules/2.6.32-5-686/build /home/mgh/Documents modules
clean :
make -C /lib/modules/2.6.32-5-686/build /home/mgh/Documents clean
root#localhost:/home/mgh/Documents# make
make -C /lib/modules/2.6.32-5-686/build /home/mgh/Documents modules
make[1]: Entering directory /usr/src/linux-headers-2.6.32-5-686'
/usr/src/linux-headers-2.6.32-5-common/scripts/Makefile.build:44: /usr/src/linux-headers-``2.6.32-5-common/scripts/basic/Makefile: No such file or directory
make[5]: *** No rule to make target `/usr/src/linux-headers-2.6.32-5-common/scripts/basic``/Makefile'. Stop.
make[4]: *** [scripts_basic] Error 2
make[3]: Nothing to be done for `/home/mgh/Documents'.
make[3]: *** No rule to make target `include/config/auto.conf', needed by `include/config``/kernel.release'. Stop.
make[2]: *** [sub-make] Error 2
make[1]: *** [all] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-5-686'
make: *** [all] Error 2
Guesswork: You did not set the M environment variable in your custom Makefile. See http://tldp.org/LDP/lkmpg/2.6/html/x181.html
And the next time, please do indeed ask a more specific question than 'What is wrong?'
I dispute that anything is wrong with make. I am very certain, though, that something is wrong with your Makefile. According to some random internet searching, try something like this:
make -C /lib/modules/2.6.32-5-686/build SUBDIRS=/home/mgh/Documents modules
This is assuming that your Makefile resides in /home/mgh/Documents.

Resources