function templates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I m using  g++ gcc version 3.3.2.

Following are the errors I got during linking. Please provide your
suggestions. The problem happens only when the function templates 
Are in a different file. 

Also they work with sun native CC ( c++) compilers.
 

Undefined                       first referenced
 symbol                             in file
void fun<int>(int)                  main.o
void fun<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > >(std::basic_string<char, std::char_traits<char>,
std::allocator<char> >)main.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status


$ cat main.cc
#include <iostream>
#include <string>
#include "test.h"

using namespace std;

main()
{

    cout << "test me " << endl;

   std::string x("abce");
    int y = 10 ;
    
    fun <std::string> (x);
    fun <int> (y);
}
$ cat fun.cc
#include "test.h"

using namespace std;

template < typename T > void fun ( T x )
{
   cout << "test............\n" ;
   cout << x << endl;

}
$ cat fun.cc
#include "test.h"

using namespace std;

template < typename T > void fun ( T x )
{
   cout << "test............\n" ;
   cout << x << endl;

}

$ g++ -c test.cc
$ g++ -c main.cc
$ g++ test.o main.o
Undefined                       first referenced
 symbol                             in file
void fun<int>(int)                  main.o
void fun<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > >(std::basic_string<char, std::char_traits<char>,
std::allocator<char> >)main.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status



_______________________________________________
Redhat-devel-list mailing list
Redhat-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/redhat-devel-list

[Index of Archives]     [Kernel Newbies]     [Red Hat General]     [Fedora]     [Red Hat Install]     [Linux Kernel Development]     [Yosemite News]

  Powered by Linux