Simple Cygwin Application Linking Problem

Michael Jäger Michael.Jaeger@hs-owl.de
Thu Oct 7 13:52:00 GMT 2010


Hello,

I’m pretty new to this whole Cygwin stuff and I have a problem building an application to an executable.

So let’s start with my little c program.

#include <test.h>


int main (void){


      printf("Hello World");
      test();
      return 0;
      
}

int test(void){

      return 0;
}
My header file is pretty simple and looks like this.

int main(void);
int test();

I just included it for screwing around with makefiles and using files that are not in the same directory, so that I had to work with path declarations.

My makefile looks as follows:

#INCLUDES ABSOLUTE
INCNETSNMPABS     = C:/cygwin/home/MJaeger/net-snmp-5.5/include   
INCCYGSTDABS      = C:/cygwin/usr/include             

#INCLUDES RELATIVE TO MAKEFILE 
SOURCEHEADERREL   = ../Headers/

#INCLUDE HEADER COMPILATION
HCOMP             = -I$(INCNETSNMPABS) -I$(INCCYGSTDABS) -I$(SOURCEHEADERREL)


#SOURCES RELATIVE TO MAKEFILE
SOURCEFILEREL           = ../Source/test.c


#LIBRARIES ABSOLUTE
LIBNETSNMPABS     = C:/cygwin/home/MJaeger/net-snmp-5.5/snmplib/
LIBCYGW32APIABS   = C:/cygwin/lib/w32api
LIBCYGSTDABS      = C:/cygwin/usr/include/d/3.4.4/std/c
LIBCYGDLLABS      = C:/cygwin/bin

#LINKER LIBRARY COMPILATION
LCOMP = -L $(LIBNETSNMPABS) -L $(LIBCYGW32APIABS) -L $(LIBCYGSTDABS) -L $(LIBCYGDLLABS)  


target.o: $(SOURCEFILEREL) $(SOURCEHEADERREL)/test.h
      gcc -o target.o $(HCOMP) -c $(SOURCEFILEREL)  
      



test.exe: target.o
      ld $(LCOMP) target.o



When calling make target.o, no error occurs. The file is created and everything seems fine. But when I’m calling make test.exe the following error occurs:

target.o:test.c(.text+0x12): undefined reference to ‘__main’
target.o:test.c(.text+0x1e): undefined reference to ‘printf’
make: *** [test.exe] Error 1

As I said I’m pretty new to this Cygwin stuff and I’m also new to writing makefiles, that’s why I just want to create a simple example.

To me it seems that the linker does not know enough library files. 
Another problem is of course, since I’m not so familiar with this stuff, I’m not even sure what to search for, so maybe someone can provide me with new knowledge or give me some hints so that I know in which topic, or sub topic I have to gain more knowledge.

Cheers and regards
Michael

 

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list