Thread: problems with makefile

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    33

    problems with makefile

    Hello,

    I have some problems writing my makefile. I'm newbie writing makefiles because I use to make small programs. I have defined a library, functions.h and functions.c that uses the GNU scientific library. And then a program that calls functions from functions.h. My makefile is like this:

    Code:
    SDIR		=	source directory
    
    CC		=	gcc
    CFLOPTS		=	-g
    CFLAGS		=	$(CFLOPTS) -I$(SDIR)
    
    CPROGS		=	main
    
    OBJETOS		=	$(SDIR)/main.o $(SDIR)/funciones.o
    
    all:$(CPROGS) $(OBJETOS)
    
    
    clean:
    	rm -f *.o $(CPROGS)
    
    
    main_RCS:$(OBJETOS)
    	$(CC) $(CFLAGS) -o $@ $(OBJETOS) -lm
    	mv $@ $(SDIR)
    
    funciones_RCS.o:$(SDIR)/funciones.c $(SDIR)/funciones.h
    	$(CC) $(CFLAGS) /usr/local/lib/libgsl.a -o $@ -lm
    	mv $@ $(SDIR)
    
    main_RCS.o:$(SDIR)/main.c $(SDIR)/funciones.h
    	mv $@ $(SDIR)
    I have an error of undefined reference in every gnu scientific library function that I use. Someone can help me?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Looks to me like you are not linking with the scientific library when producing the final program (main_RCS).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    33
    But the final program doesn't use scientific library functions, it only calls one function from funciones.c

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by bartleby84 View Post
    But the final program doesn't use scientific library functions, it only calls one function from funciones.c
    Yes, but you are not linking functiones.o with a libray until you link it together into the final executable. When you compile the "half-way-step", it will just produce an object file of the C file, and not do any linking.

    If you add -v to the CFLOPTS variable, you will see exactly what the compiler does (which is quite a bit). You should only see a "collect2" stage in the final linking step, which is the target here:
    main_RCS:$(OBJETOS)

    If you see collect2 elsewhere, then you have something else wrong (and it may be that you need a -c on the cases where you produce .o files - without seeing the actual output of what make does when you run it, I can't say for sure if it does the right thing or not).


    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Mar 2007
    Posts
    33
    Ok thanks, I'm going to try that!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Building a project using a Makefile
    By starcatcher in forum Windows Programming
    Replies: 2
    Last Post: 11-23-2008, 11:50 PM
  2. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  3. makefile problems
    By cpjust in forum C++ Programming
    Replies: 4
    Last Post: 06-16-2008, 03:14 AM
  4. using a makefile / gdb info
    By dinjas in forum C Programming
    Replies: 2
    Last Post: 02-22-2005, 06:42 PM
  5. Need help with Makefile
    By xshapirox in forum C++ Programming
    Replies: 14
    Last Post: 09-28-2004, 03:32 PM