Linkage problem (maybe)

This is a discussion on Linkage problem (maybe) within the C++ Programming forums, part of the General Programming Boards category; Hi everyone. I am making a program using templates. I'm not very good with templates. Also, I'm using a makefile. ...

  1. #1
    Registered User nepper271's Avatar
    Join Date
    Jan 2008
    Location
    Brazil
    Posts
    50

    Linkage problem (maybe)

    Hi everyone. I am making a program using templates. I'm not very good with templates. Also, I'm using a makefile. I'm not good with makefiles either. The thing is, when I compile, I receive the following error message:

    Code:
    main.o(.gnu.linkonce.t._Z9algoritmoI6matriz5vetor9simetricaERT0_RKT1_RKS3_RKT_S9_S9_+0x484): In function `vetor& algoritmo<matriz, vetor, simetrica>(simetrica const&, vetor const&, matriz const&, vetor const&, vetor const&)':
    /home/abel/Matriz_com_Templates/metodos.h:144: undefined reference to `vetor& Inverso<vetor>(vetor const&)'
    main.o(.gnu.linkonce.t._Z9algoritmoI6matriz5vetor9simetricaERT0_RKT1_RKS3_RKT_S9_S9_+0x6f5):/home/abel/Matriz_com_Templates/metodos.h:156: undefined reference to `vetor& Inverso<vetor>(vetor const&)'
    ...
    it repeats for some other lines. This problem arises when I make a call to a function included in
    Code:
    metodos.h
    . Those undefined references, are included in
    Code:
    ferramentas.h
    . I have included ferramentas.h in the metodos.h. I don't have .cpp for these files. My makefile is the following ( a part of it):

    Code:
    matriz : matriz.o vetor.o vetor_esp.o esparsa.o simetrica.o metodos.o main.o 
    	g++ -g -o matriz matriz.o vetor.o vetor_esp.o esparsa.o simetrica.o main.o
    
    main.o : testematriz.cpp ferramentas.h metodos.h
    	g++ -g -c testematriz.cpp -o main.o
    
    metodos.o : metodos.h
    	g++ -g -c metodos.h
    
    matriz.o : matriz.cpp matriz.h
    	g++ -g -c matriz.cpp
    
    ...
    When I call for another function in the same "metodos.h" library, it works.
    I don't have a clue of what is going wrong, if anyone can help me, I would be very thankful.

    Thank you,
    Nepper271.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What does your implementation of "Inverso" look like?

    --
    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 nepper271's Avatar
    Join Date
    Jan 2008
    Location
    Brazil
    Posts
    50
    Inverso takes an element of the type 'vetor' (a vector) and returns another element of 'vetor' with the inverse of each element, i.e.

    Code:
    if v = (v1, v2, ..., vn), inverso(v) = (1/v1, 1/v2, ..., 1/vn).
    But this problem is happening with all function called by 'metodos.h' that are in 'ferramentas.h', not only 'inverso'

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    No, I'm not asking what it DOES, I'm asking what the prototype of the function looks like. Peering into my plastic ball [plastic balls are not as good at seeing the future as crystal balls, but they are a lot less expencive], I predict you are missing a const or some such.

    --
    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 nepper271's Avatar
    Join Date
    Jan 2008
    Location
    Brazil
    Posts
    50
    Oh, sorry, here it is:
    Code:
    template <typename tipo_matriz, typename tipo_vetor>
    tipo_vetor & Inverso(tipo_vetor const & x) {
    	int n = x.size();
    	tipo_vetor *y = new tipo_vetor(n);
    	for (int i = 1; i <= n; i++) (*y)(i) = 1.0/x(i);
    	return *y;
    }

  6. #6
    Registered User nepper271's Avatar
    Join Date
    Jan 2008
    Location
    Brazil
    Posts
    50
    Thank you everyone, but the problem is solved, and had nothing to do with anything I said before
    I had just put some extra typenames in some functions, (like the above, see?)

    Thank you all,
    Nepper271

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    See, that plastic ball is almost useful

    --
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21