i have recently started to use netbeans to program in c. i usually use codeblocks. i have installed tdm-gcc and msys for this purpose.
the programs are getting compiled successfully. but on execution, it shows build failed(exit value 2).
"/C/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/f/NetBeansProjects/C_Programs'
"/C/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW_TDM-Windows/c_programs.exe
make.exe[2]: Entering directory `/f/NetBeansProjects/C_Programs'
mkdir -p build/Debug/MinGW_TDM-Windows
rm -f "build/Debug/MinGW_TDM-Windows/main.o.d"
gcc -c -g -MMD -MP -MF "build/Debug/MinGW_TDM-Windows/main.o.d" -o build/Debug/MinGW_TDM-Windows/main.o main.c
mkdir -p dist/Debug/MinGW_TDM-Windows
gcc -o dist/Debug/MinGW_TDM-Windows/c_programs build/Debug/MinGW_TDM-Windows/main.o build/Debug/MinGW_TDM-Windows/structure_union.o
build/Debug/MinGW_TDM-Windows/structure_union.o: In function `main':
F:\NetBeansProjects\C_Programs/structure_union.c:32: multiple definition of `main'
build/Debug/MinGW_TDM-Windows/main.o:F:\NetBeansProjects\C_Programs/main.c:15: first defined here
collect2.exe: error: ld returned 1 exit status
make.exe[2]: *** [dist/Debug/MinGW_TDM-Windows/c_programs.exe] Error 1
make.exe[2]: Leaving directory `/f/NetBeansProjects/C_Programs'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/f/NetBeansProjects/C_Programs'
make.exe": *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 657ms)
can somebody help me with what im doing wrong?
You have multiple main() functions in your project:
[…]/structure_union.c:32: multiple definition of `main'
It seems there's one in structure_union and another one in main.c (line 15).
C allows only one definition of main(); remove one of these and it should work.
Related
I get a build error when trying to build a flex and lemon project with CMake. Can you help me find what is wrong?
$ make
/usr/bin/cmake -H/home/dac/ClionProjects/openshell -B/home/dac/ClionProjects/openshell --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/dac/ClionProjects/openshell/CMakeFiles /home/dac/ClionProjects/openshell/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/dac/ClionProjects/openshell'
make -f CMakeFiles/lemon.dir/build.make CMakeFiles/lemon.dir/depend
make[2]: Entering directory '/home/dac/ClionProjects/openshell'
cd /home/dac/ClionProjects/openshell && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell/CMakeFiles/lemon.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/dac/ClionProjects/openshell'
make -f CMakeFiles/lemon.dir/build.make CMakeFiles/lemon.dir/build
make[2]: Entering directory '/home/dac/ClionProjects/openshell'
make[2]: Nothing to be done for 'CMakeFiles/lemon.dir/build'.
make[2]: Leaving directory '/home/dac/ClionProjects/openshell'
/usr/bin/cmake -E cmake_progress_report /home/dac/ClionProjects/openshell/CMakeFiles 1
[ 16%] Built target lemon
make -f CMakeFiles/openshell.dir/build.make CMakeFiles/openshell.dir/depend
make[2]: Entering directory '/home/dac/ClionProjects/openshell'
cd /home/dac/ClionProjects/openshell && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell/CMakeFiles/openshell.dir/DependInfo.cmake --color=
Scanning dependencies of target openshell
make[2]: Leaving directory '/home/dac/ClionProjects/openshell'
make -f CMakeFiles/openshell.dir/build.make CMakeFiles/openshell.dir/build
make[2]: Entering directory '/home/dac/ClionProjects/openshell'
/usr/bin/cmake -E cmake_progress_report /home/dac/ClionProjects/openshell/CMakeFiles 2
[ 33%] Building C object CMakeFiles/openshell.dir/main.c.o
/usr/bin/cc -Wall -Werror -O3 -std=c99 -I/usr/include/readline -o CMakeFiles/openshell.dir/main.c.o -c /home/dac/ClionProjects/openshell/main.c
Linking C executable openshell
/usr/bin/cmake -E cmake_link_script CMakeFiles/openshell.dir/link.txt --verbose=1
/usr/bin/cc -Wall -Werror -O3 -std=c99 CMakeFiles/openshell.dir/main.c.o CMakeFiles/openshell.dir/errors.c.o CMakeFiles/openshell.dir/util.c.o CMakeFiles/openshell.dir/stack.c.o CMakeFiles/openshell.dir/flex/shellparser.c.o -o openshell -rdynamic -lreadline
CMakeFiles/openshell.dir/main.c.o: In function `main':
main.c:(.text.startup+0xef): undefined reference to `yylex_init'
main.c:(.text.startup+0x100): undefined reference to `yyset_in'
main.c:(.text.startup+0x12e): undefined reference to `yylex'
main.c:(.text.startup+0x13a): undefined reference to `yyget_text'
main.c:(.text.startup+0x178): undefined reference to `yylex_destroy'
collect2: error: ld returned 1 exit status
CMakeFiles/openshell.dir/build.make:188: recipe for target 'openshell' failed
make[2]: *** [openshell] Error 1
make[2]: Leaving directory '/home/dac/ClionProjects/openshell'
CMakeFiles/Makefile2:98: recipe for target 'CMakeFiles/openshell.dir/all' failed
make[1]: *** [CMakeFiles/openshell.dir/all] Error 2
make[1]: Leaving directory '/home/dac/ClionProjects/openshell'
Makefile:78: recipe for target 'all' failed
make: *** [all] Error 2
My CMake build file is
cmake_minimum_required (VERSION 2.6)
project (openshell)
set(CMAKE_VERBOSE_MAKEFILE on)
include_directories(/usr/include/readline)
#### Lemon bootstrap ####
ADD_EXECUTABLE(lemon lemon.c)
file(GLOB SOURCES "./*.c")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -O3 -std=c99")
add_executable(openshell main.c openshell.h errors.c errors.h util.c util.h stack.c stack.h flex/shellparser.c flex/shellscanner.l flex/shellscanner.h)
target_link_libraries(openshell readline)
You're not linking the Flex library, so you will get linker errors for any Flex functions you use, such as yyset_in.
You can use find_package(FLEX) and after using FLEX_TARGET to define your Flex targets, you can then use something like the following:
# Note: I use "ShellScanner" below as in FLEX_TARGET(ShellScanner flex/shellscanner.l ...)
add_executable(openshell
...
flex/shellparser.c
${FLEX_ShellScanner_OUTPUTS}
)
target_link_libraries(openshell ${READLINE_LIBRARY} ${FLEX_LIBRARIES})
See FindFLEX for more information.
However, I don't see a FindReadline.cmake module with the other modules that CMake provides by default, so you might have to create one yourself or use an existing one such as the one I just linked. There's also the Editline library, which provides similar functionality, and you can use an existing FindEditline.cmake file for that too.
My problem is the following one:
When installing Axis2/c under the guidance of http://petio.org/ws/web_services_page7.html , which seems to be an adjusted manual from the official site I have a problem right after executing the make command in terminal.
At exactly this point:
$ cd /tmp/axis/axis2c-src-1.6.0
$ ./configure --prefix=${AXIS2C_HOME} --enable-libxml2=yes
$ make
I get this error:
XXX#XXXPC:~/Tools/axis2c/axis2c-src-1.5.0$ make
make all-recursive
make[1]: Entering directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0'
Making all in util
make[2]: Entering directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util'
make all-recursive
make[3]: Entering directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util'
Making all in src
make[4]: Entering directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util/src'
Making all in platforms/unix
make[5]: Entering directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util/src/platforms/unix'
/bin/bash ../../../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I../../.. -I../../../include -I../../../include/platforms -I../../../include/platforms/unix -g -O2 -D_LARGEFILE64_SOURCE -ansi -Wall -Werror -Wno-implicit-function-declaration -D_GNU_SOURCE -MT uuid_gen_unix.lo -MD -MP -MF .deps/uuid_gen_unix.Tpo -c -o uuid_gen_unix.lo uuid_gen_unix.c
gcc -DHAVE_CONFIG_H -I. -I../../.. -I../../../include -I../../../include/platforms -I../../../include/platforms/unix -g -O2 -D_LARGEFILE64_SOURCE -ansi -Wall -Werror -Wno-implicit-function-declaration -D_GNU_SOURCE -MT uuid_gen_unix.lo -MD -MP -MF .deps/uuid_gen_unix.Tpo -c uuid_gen_unix.c -fPIC -DPIC -o .libs/uuid_gen_unix.o
**uuid_gen_unix.c: In function ‘axutil_uuid_gen_v1’:
uuid_gen_unix.c:62:20: error: variable ‘tv’ set but not used [-Werror=unused-but-set-variable]**
cc1: all warnings being treated as errors
make[5]: *** [uuid_gen_unix.lo] Error 1
make[5]: Leaving directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util/src/platforms/unix'
make[4]: *** [all-recursive] Error 1
make[4]: Leaving directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util/src'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0'
make: *** [all] Error 2
I am not able to understand the reason why this error is being produced.
Because 1.6.0 version is down, I am using the 1.5.0 source version of axis2/c from the official site : http://axis.apache.org/axis2/c/core/download.cgi .
I have additionally installed Apache2 and libxml2, OpenSSL, cURL, libiconv, and zlib.
libraries.
I need your help because I am trying to build a serious project.
Thanks in advance.
Link to mirror of original Axis2/C-1.6.0 source distribution is here.
The main problem is with -Werror flag.
To compile original Axis2/C with modern compiler you must remove -Werror string from build scripts. To do that run this command after unpacking tarball:
find -type f -name configure -exec sed -i '/CFLAGS/s/-Werror//g' {} \;
Then configure and make Axis2/C.
Note: Original Axis2/C-1.6.0 has many issues like memory leaks and crashes. Consider using Axis2/C unofficial project instead. Most critical Axis2/C-1.6.0's issues is fixed within that project.
Also it have additional features https://code.google.com/p/axis2c-unofficial/wiki/IssuesList like JSON support and enhanced CURL-based transport authentication (and some other features).
There is an manual on how to install Axis2/C unofficial on Linux.
I'm trying to build some native libraries in C that will speed up the monte-carlo simulation for a Java project. I'm doing this on Netbeans 7.0.1, using MINGW
I'm using the mtwist source code of Geof Kuenning (http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html) to provide Mersenne Twister pseudorandom numbers.
I have three different models to simulate, and each compiles fine on its own (with output to file rather than using the JNI). However, when I combine the three models under the JNI header file, I start to get a long list of errors when I try to build:
CLEAN SUCCESSFUL (total time: 7s)
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory /c/Users/Tom/Documents/LongMemoryModels/longMemModels'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW_1- Windows/liblongMemModels.dll
make[2]: Entering directory/c/Users/Tom/Documents/LongMemoryModels/longMemModels'
mkdir -p build/Debug/MinGW_1-Windows
rm -f build/Debug/MinGW_1-Windows/longmem.o.d
gcc.exe -std=c99 -c -g -I../../../../../Program\ Files/Java/jdk1.7.0/include/ -I../../../../../Program\ Files/Java/jdk1.7.0/include/win32 -MMD -MP -MF build/Debug/MinGW_1-Windows/longmem.o.d -o build/Debug/MinGW_1-Windows/longmem.o longmem.c
mkdir -p build/Debug/MinGW_1-Windows/_ext/2069311947
rm -f build/Debug/MinGW_1-Windows/_ext/2069311947/mtwist.o.d
gcc.exe -std=c99 -c -g -I../../../../../Program\ Files/Java/jdk1.7.0/include/ -I../../../../../Program\ Files/Java/jdk1.7.0/include/win32 -MMD -MP -MF build/Debug/MinGW_1-Windows/_ext/2069311947/mtwist.o.d -o build/Debug/MinGW_1-Windows/_ext/2069311947/mtwist.o ../../../../../cinclude/mtwist/mtwist.c
mkdir -p build/Debug/MinGW_1-Windows/_ext/2069311947
rm -f build/Debug/MinGW_1-Windows/_ext/2069311947/randistrs.o.d
gcc.exe -std=c99 -c -g -I../../../../../Program\ Files/Java/jdk1.7.0/include/ -I../../../../../Program\ Files/Java/jdk1.7.0/include/win32 -MMD -MP -MF build/Debug/MinGW_1-Windows/_ext/2069311947/randistrs.o.d -o build/Debug/MinGW_1-Windows/_ext/2069311947/randistrs.o ../../../../../cinclude/mtwist/randistrs.c
mkdir -p dist/Debug/MinGW_1-Windows
gcc.exe -std=c99 -shared -o dist/Debug/MinGW_1-Windows/liblongMemModels.dll build/Debug/MinGW_1-Windows/longmem.o build/Debug/MinGW_1-Windows/_ext/2069311947/mtwist.o > build/Debug/MinGW_1-Windows/_ext/2069311947/randistrs.o
build/Debug/MinGW_1-Windows/_ext/2069311947/mtwist.o: In function mts_lrand':
C:\Users\Tom\Documents\LongMemoryModels\longMemModels/../../../../../cinclude/mtwist/mtwist.h:402: multiple definition ofmts_lrand'
build/Debug/MinGW_1-Windows/longmem.o:C:/cinclude/mtwist/mtwist.h:402: first defined here
build/Debug/MinGW_1-Windows/_ext/2069311947/mtwist.o: In function mts_llrand':
C:\Users\Tom\Documents\LongMemoryModels\longMemModels/../../../../../cinclude/mtwist/mtwist.h:431: multiple definition ofmts_llrand'
build/Debug/MinGW_1-Windows/longmem.o:C:/cinclude/mtwist/mtwist.h:431: first defined here
[...]
build/Debug/MinGW_1-Windows/_ext/2069311947/randistrs.o: In function mts_lrand':
C:\Users\Tom\Documents\LongMemoryModels\longMemModels/../../../../../cinclude/mtwist/mtwist.h:402: multiple definition ofmts_lrand'
build/Debug/MinGW_1-Windows/longmem.o:C:/cinclude/mtwist/mtwist.h:402: first defined here
build/Debug/MinGW_1-Windows/_ext/2069311947/randistrs.o: In function mts_llrand':
C:\Users\Tom\Documents\LongMemoryModels\longMemModels/../../../../../cinclude/mtwist/mtwist.h:431: multiple definition ofmts_llrand'
build/Debug/MinGW_1-Windows/longmem.o:C:/cinclude/mtwist/mtwist.h:431: first defined here
[...]
make[2]: Leaving directory /c/Users/Tom/Documents/LongMemoryModels/longMemModels'
make[1]: Leaving directory/c/Users/Tom/Documents/LongMemoryModels/longMemModels'
collect2.exe: error: ld returned 1 exit status
make[2]: * [dist/Debug/MinGW_1-Windows/liblongMemModels.dll] Error 1
make[1]: [.build-conf] Error 2
make: ** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 22s)
(here the elipsis, [...], denotes similar errors that I have omitted)
As you can see, the multiple inclusions seem to relate to the mtwist.h header rather than the JNI header. Moreover, I get the same errors trying to build the JNI project even when mtwist has already been successfully built as a static or dynamic library...
I don't want this question to be too much of an essay, and I'm hoping that error will reveal an obvious error to someone more savvy than me. BUT, I'll post source code too, if this isn't enough to point to a solution.
Please help me resolve this build error if you can.
Tom
EDIT: to make the include structure clearer than in the comments...
In the current arrangement:
[JNI models header].h includes jni.h
mtwist.h includes stdio.h, stdint.h
randistrs.h, includes mtwist.h
[individual model functions].c includes stdio.h stdlib.h math.h mtwist/mtwist.h mtwist/randistrs.h jni.h (unnecessary I suppose)
mtwist.c includes inttypes.h stdio.h stdlib.h sys/timeb.h mtwist.h
randistrs.c includes mtwist.h randistrs.h math.h stdlib.h
All of the .h files have inclusion guards using #ifndef
i guess it's a case of multiple inclusion of prototype.Please try guarding using #ifdef #endif Macro in mtwist.h, for all those prototypes which are giving error.
The following make output is showing an undefined reference, and I am not sure what is causing it. Could someone help?
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/cygdrive/g/workspace/c_cpp/MongoDriverTest'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin_4.x-Windows/mongodrivertest.exe
make[2]: Entering directory `/cygdrive/g/workspace/c_cpp/MongoDriverTest'
mkdir -p build/Debug/Cygwin_4.x-Windows
rm -f build/Debug/Cygwin_4.x-Windows/main.o.d
gcc -std=c99 -c -g -I../mongodb-mongo-c-driver/src/\*.c -MMD -MP -MF build/Debug/Cygwin_4.x-Windows/main.o.d -o build/Debug/Cygwin_4.x-Windows/main.o main.c
mkdir -p dist/Debug/Cygwin_4.x-Windows
gcc -std=c99 -o dist/Debug/Cygwin_4.x-Windows/mongodrivertest build/Debug/Cygwin_4.x-Windows/main.o
nbproject/Makefile-Debug.mk:61: recipe for target `dist/Debug/Cygwin_4.x-Windows/mongodrivertest.exe' failed
make[2]: Leaving directory `/cygdrive/g/workspace/c_cpp/MongoDriverTest'
nbproject/Makefile-Debug.mk:58: recipe for target `.build-conf' failed
make[1]: Leaving directory `/cygdrive/g/workspace/c_cpp/MongoDriverTest'
nbproject/Makefile-impl.mk:39: recipe for target `.build-impl' failed
build/Debug/Cygwin_4.x-Windows/main.o: In function `main':
/cygdrive/g/workspace/c_cpp/MongoDriverTest/main.c:19: undefined reference to `_mongo_connect'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/Cygwin_4.x-Windows/mongodrivertest.exe] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
And this is the content of my main.c:
#include <stdio.h>
#include <stdlib.h>
#include "../mongodb-mongo-c-driver/src/mongo.h"
int main(int argc, char** argv) {
int status;
mongo conn[1];
status=mongo_connect(conn, "127.0.0.1", 27017);
return EXIT_SUCCESS;
}
It was working two days ago, I reinstalled the OS and now it's not working anymore and I don't seem to find the cause. mongo.h exists, mongo.o is there as well. mongo_connect is in mongo.c. Any idea?
Your link line is:
gcc -std=c99 -o dist/Debug/Cygwin_4.x-Windows/mongodrivertest build/Debug/Cygwin_4.x-Windows/main.o
It doesn't tell GCC where to collect mongo_connect() from. You need to specify the Mongo library on the command line.
Given the include line in your source code:
#include "../mongodb-mongo-c-driver/src/mongo.h"
You might add options:
-L../mongodb-mongo-c-driver/lib -lmongo
to the link line. Both the location and the library name are guesses. That would pick up libmongo.dll or libmongo.lib from the specified directory.
If you can't find the library under the ../mongodb-mongo-c-driver directory, somewhere, you may have to build and install it. Alternatively, it may already be installed and you simply need to ensure you are referencing the correct locations where it is installed.
Also, as a general rule, avoid pathnames like that in the source code. You should specify:
#include "mongo.h"
and supply a compile line option to specify where to look for it:
-I../mongodb-mongo-c-driver/src
See also: What are the benefits of a relative path such as #include "../include/header.h" for a header?.
I installed netbeans to write code in C. But there is problem using Mingw compilers. It works just fine, till i try to run the project.
First it was unable to find cc1.exe while trying to run it. When i found it and manually copied into the same folder there is just another error.
"C:/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
C:\bin\make.exe[1]: Entering directory `D:/1/2/Skola/IZP/programovani/projekt4netbeans/CppApplication_6'
"C:/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW_1-Windows/cppapplication_6.exe
C:\bin\make.exe[2]: Entering directory `D:/1/2/Skola/IZP/programovani/projekt4netbeans/CppApplication_6'
mkdir -p build/Debug/MinGW_1-Windows
rm -f build/Debug/MinGW_1-Windows/main.o.d
gcc.exe -c -g -MMD -MP -MF build/Debug/MinGW_1-Windows/main.o.d -o build/Debug/MinGW_1-Windows/main.o main.c
cc1: error: command line option '-lang-c' is valid for the driver but not for C
C:\bin\make.exe[2]: *** [build/Debug/MinGW_1-Windows/main.o] Error 1
C:\bin\make.exe[2]: Leaving directory `D:/1/2/Skola/IZP/programovani/projekt4netbeans/CppApplication_6'
C:\bin\make.exe[1]: *** [.build-conf] Error 2
C:\bin\make.exe[1]: Leaving directory `D:/1/2/Skola/IZP/programovani/projekt4netbeans/CppApplication_6'
C:\bin\make.exe: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 2s)
if someone could help me with that.. thanks :)
Make shure you have current versions of Netbeans and MinGw and that you have a correct installation (Configuring the NetBeans IDE for C/C++/Fortran).
On mingw you should not use make from mingw/bin, but the one from msys (<mingw>/msys/1.0/bin/make.exe)