So, after spending a couple of hours of manually configuring autotools, I finally managed to create a makefile for my project. Only problem? It gives me problems with the linker.
Let me explain it better: I have a project that is divided in several subprograms, all of which are to be linked to the main program, main.c. My problem is that while I can compile everything properly with gcc, make gives me the dreaded collect2: ld returned 1 exit status error, naming an undefined reference to main as the reason. Now, we all know it's a linking error, and as a proof of that I could compile all the files without linking them adding -c among the CFLAGS in Makefile.am. But we already knew that, I guess.
My question is: what should I a开发者_JS百科dd to the Makefile.am (the one inside my src folder, I guess?) file in order to let it link all the files to one another and not separately, so that the linker will find the entry point in main.o? Basically, the equivalent of running "gcc program1.c program2.c main.c". I know automake does it because it builds the files progressively, one at the time, and I know it's a dumb question but it's driving me crazy anyway. It's the first time I use autotools, help me make it not the last!
If foo
is your program's name and you're not doing anything fancy,
bin_PROGRAMS = foo
foo_SOURCES = program1.c program2.c main.c
foo_LDADD = # any other libraries go here as -l arguments
should be a sufficient Makefile.am
.
精彩评论