I am confused by how to make a archive. Here is the code I use:
I first have a vector.h file
Also a vector.cc file contains its definition.Code://vector.h namespace TEST{ int add(int x, int y); }
Code://vector.cc #include <iostream> #include "vector.h" int TEST::add(int x, int y){ return (x+y); } int main(){ std::cout<<TEST::add(1,1)<<std::endl; return 0; }
I use the following command to make a libvec.a
Then here is the program uses libvec.ag++ -c vector.cc
ar rcs libvec.a vector.o
So far so good. Finally I use the following command to make main program using libvec.aCode://main.cc #include <iostream> #include "vector.h" using namespace std; int main(){ cout<<TEST::add(2,3)<<endl; return 0; }
It reports:Code:g++ -o main main.cc libvec.a
libvec.a(vector.o)(.text+0xc): In function `main':
: multiple definition of `main'
/tmp/ccRdvIKb.o(.text+0x0): first defined here
collect2: ld returned 1 exit status
I am confused. It seems that I can't define main() function for an archive. But I have seen many code that has main() function but also is compiled for an archive. Anybody has a clue what is wrong?



LinkBack URL
About LinkBacks


