Netbeans Error when running a simple c program - c

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?

Related

KBuild fails while compiling without debugging flag

I am trying to compile a very simple module, but it fails to create *.ko when i am not adding -g flag. Here is the source code:
#include <linux/init.h>
#include <linux/module.h>
static int simple_test_init(void){
printk(KERN_INFO "Hello Kernel!");
return 0;
}
static void simple_test_exit(void){
printk(KERN_INFO "Goodbye Kernel!");
}
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Simple test module");
module_init(simple_test_init);
module_exit(simple_test_exit);
And here is GCC/Makefile.
KBUILD_CFLAGS := -Werror -fcf-protection=branch
obj-m += test.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
And finally the output of GCC.
make -C /lib/modules/5.19.3-arch1-1/build M=/test modules
make[1]: Entering directory '/usr/lib/modules/5.19.3-arch1-1/build'
CC [M] /test/test.o
/test/test.o: warning: objtool: folio_flags+0x29: 'naked' return found in RETHUNK build
/test/test.o: warning: objtool: simple_test_init+0x22: 'naked' return found in RETHUNK build
/test/test.o: warning: objtool: simple_test_exit+0x1e: 'naked' return found in RETHUNK build
/test/test.o: warning: objtool: folio_flags+0x29: missing int3 after ret
/test/test.o: warning: objtool: simple_test_init+0x22: missing int3 after ret
/test/test.o: warning: objtool: simple_test_exit+0x1e: missing int3 after ret
MODPOST /test/Module.symvers
CC [M] /test/test.mod.o
LD [M] /test/test.ko
BTF [M] /test/test.ko
pahole: /test/test.ko: No such file or directory
make[3]: *** [scripts/Makefile.modfinal:60: /test/test.ko] Error 1
make[3]: *** Deleting file '/test/test.ko'
make[2]: *** [scripts/Makefile.modpost:134: __modpost] Error 2
make[1]: *** [Makefile:1763: modules] Error 2
make[1]: Leaving directory '/usr/lib/modules/5.19.3-arch1-1/build'
make: *** [Makefile:6: all] Error 2
Thank you.

C Programming with NetBeans on Mac OSX

I am pretty new to programming and I am trying to learn C. I installed net beans 8.0.2 on a mac with OS 10.10.3. And I tried to run my first code:
/* HelloWorld.c */
#include <stdio.h>
#include <stdlib.h>
int main(void) {
puts("Hello PROGC"); /* prints > Hello PROGC */
return EXIT_SUCCESS;
}
Now I am getting this Error Message:
"/Library/Developer/CommandLineTools/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
"/Library/Developer/CommandLineTools/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-MacOSX/cppapplication_1
mkdir -p build/Debug/GNU-MacOSX
rm -f "build/Debug/GNU-MacOSX/Hello World.o.d"
gcc -c -g -MMD -MP -MF "build/Debug/GNU-MacOSX/Hello World.o.d" -o build/Debug/GNU-MacOSX/Hello\ World.o Hello\ World.c
mkdir -p dist/Debug/GNU-MacOSX
gcc -o dist/Debug/GNU-MacOSX/cppapplication_1 build/Debug/GNU-MacOSX/Hello\ World.o build/Debug/GNU-MacOSX/main.o
duplicate symbol _main in:
build/Debug/GNU-MacOSX/Hello World.o
build/Debug/GNU-MacOSX/main.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]: *** [dist/Debug/GNU-MacOSX/cppapplication_1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 687ms)
Could you please let me know what I have to change? Many thanks in advance!

using header in netbeans C

I tried to compile a simple C program with a header, a main, and another source file in Netbeans but it didn't work. I always get a huge error message.
I have absolutely no idea what I can do to make it work. Hope you guy can help me.
console:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/***/***/***/***/***/headertest'
nbproject/Makefile-Debug.mk:73: warning: overriding commands for target `build/Debug/GNU-Linux-x86/header.o'
nbproject/Makefile-Debug.mk:68: warning: ignoring old commands for target `build/Debug/GNU-Linux-x86/header.o'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/headertest
make[2]: Entering directory `//home/***/***/***/***/***/headertest'
nbproject/Makefile-Debug.mk:73: warning: overriding commands for target `build/Debug/GNU-Linux-x86/header.o'
nbproject/Makefile-Debug.mk:68: warning: ignoring old commands for target `build/Debug/GNU-Linux-x86/header.o'
mkdir -p build/Debug/GNU-Linux-x86
rm -f "build/Debug/GNU-Linux-x86/header.o.d"
gcc -c -g -MMD -MP -MF "build/Debug/GNU-Linux-x86/header.o.d" -o build/Debug/GNU-Linux-x86/header.o header.h
mkdir -p build/Debug/GNU-Linux-x86
rm -f "build/Debug/GNU-Linux-x86/main.o.d"
gcc -c -g -MMD -MP -MF "build/Debug/GNU-Linux-x86/main.o.d" -o build/Debug/GNU-Linux-x86/main.o main.c
mkdir -p dist/Debug/GNU-Linux-x86
gcc -o dist/Debug/GNU-Linux-x86/headertest build/Debug/GNU-Linux-x86/header.o build/Debug/GNU-Linux-x86/header.o build/Debug/GNU-Linux-x86/main.o
/usr/bin/ld:build/Debug/GNU-Linux-x86/header.o: file format not recognized; treating as linker script
/usr/bin/ld:build/Debug/GNU-Linux-x86/header.o:1: syntax error
collect2: error: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/headertest] Error 1
make[2]: Leaving directory `/home/***/***/***/***/***/headertest'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/***/***/***/***/***/headertest'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 283ms)
Here is the rest of my code:
main.c
#include <stdio.h>
#include <stdlib.h>
#include "header.h"
int main(int argc, char** argv) {
lol();
return (EXIT_SUCCESS);
}
header.c
#include "header.h"
void lol(){
printf("lol");
}
header.h
#ifndef HEADER_H
#define HEADER_H
#ifdef __cplusplus
extern "C" {
#endif
void lol();
#ifdef __cplusplus
}
#endif
#endif /* HEADER_H */
You have not included stdio.h. Your lol() function doesn't know printf().
Put a #include <stdio.h> either into header.c or header.h.

undefined reference to `main' using Autotools

I have a little program, when I run make this error appears:
$ make
make all-recursive
make[1]: se ingresa al directorio «/home/foo/boolham»
Making all in src
make[2]: se ingresa al directorio «/home/foo/boolham/src»
/bin/bash ../libtool --tag=CC --mode=link gcc -std=gnu99 -g -O2 -o set set.o
libtool: link: gcc -std=gnu99 -g -O2 -o set set.o
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
make[2]: *** [set] Error 1
make[2]: se sale del directorio «/home/foo/boolham/src»
make[1]: *** [all-recursive] Error 1
make[1]: se sale del directorio «/home/foo/boolham»
make: *** [all] Error 2
My Makefile.am has:
lib_LTLIBRARIES = libfsequence.la
libfsequence_la_SOURCES = fsequence.c fsequence.h
bin_PROGRAMS = set main
main_SOURCES = main.c main.h
set_SOURCES = set.c set.h
main_LDADD = libfsequence.la
main.c has only int main() function, set.c has sets functions and fsequences.c has functions to generate sequences of numbers. fsequences.c includes set.h as a utility functions and main.c includes fsequences.h.
What's wrong with my code?
It is a little shot in the dark, but I guess your set.c file is a file without main. Then You should not treat it as a program - it should be compiled with -c option (so .o file will be generated and linked with main).
I'm not familiar with autotools, but you should check some examples how to do that.
EDIT:
according to: http://socgsa.cs.clemson.edu/seminar/tools06/resources/08_autotools/automake.htm you just should remove 'set' from 'bin_PROGRAMS'

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