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.
Related
I am refactoring my personal libc and I need to redo my makefile. So far so good, But suddenly, the variables aren't included in the commands executed.
Here's the trouble so far:
➜ libft git:(master) ✗ make
clang -c -o srcs/core/ft_add_to_array.o srcs/core/ft_add_to_array.c
srcs/core/ft_add_to_array.c:13:10: fatal error: 'core/core.h' file not found #include <core/core.h>
^
1 error generated.
<builtin>: recipe for target 'srcs/core/ft_add_to_array.o' failed
make: *** [srcs/core/ft_add_to_array.o] Error 1
Which i suppose come from this line of my makefile :
%.o:$(SRC_PATH)/%.c
$(CC) $(FLAGS) $(INC) -o $# -c $<
So what i've come up so far is that the FLAGS and INC variables are simply not included... Any ideas why ?
I've found the solution
I've removed the addsuffix part and added srcs/ to each line of the sources i've declared manually and it compiled fine !
Here's the makefile after my modifications
Thanks guys
My teacher is not the best at explain C so I'm having a bit of trouble understanding the connection of makefiles. I have already added the code for complex.c, complex.h, and main.c. I'm just having trouble compiling it all using the make command. I followed the example on the powerpoint he handed up and I don't understand why its failing to get to complex.
makefile
complex: main.o complex.o
gcc -o complex main.o complex.o
main.o: main.c complex.h
gcc -c main.c -lm
complex.o: complex.c complex.h
gcc -c complex.c -lm
clean:
rm*.o complex
ls
main.o
main.o: complex.h
gcc -c main.c
complex.o
complex.o: complex.h
gcc -c complex.c
Error
mason% make
gcc -o complex main.o complex.o
ld: fatal: file main.o: unknown file type
ld: fatal: file processing errors. No output written to complex
collect2: error: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `complex'
It looks like you have put Makefile fragments inside main.o and complex.o. These should be generated by the compiler, not by you.
Delete these files, and make again.
Additionally, your make clean rule is missing a space.
clean:
rm *.o complex
ls
One more thing. No need for -lm in the compile lines.
main.o: main.c complex.h
gcc -c main.c
complex.o: complex.c complex.h
gcc -c complex.c
You should add -lm at the linking phase.
complex: main.o complex.o
gcc -o complex main.o complex.o -lm
The "Makefile" defines and controls the build dependencies.
For example, you can't build the main executable binary without first building the binary object/module files that go with it. In this case, those are main.o and complex.o.
Generally any object file you need also needs a rule (though some rules can use "wildcards" to build more).
This is all rather academic. Best to take errors at their word and try to disprove them (this one basically says that main.o exists and is incorrect). In this case the hypothesis that main.o exists is supported by the fact that it didn't compile when you ran the make command.
Until you learn more you could invoke "make" using "targets". Like: make clean and make complex. It might help bring clarity.
A lot of makefiles put an "all" target to sort of reset the build. That then depends on "clean" and the executable and library targets. Like:
all: clean complex
So then you "make all" to clean and build.
A good tutorial is here. Mrbook Makefile Tutorial
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.
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.
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?.