lemonsf
November 12th, 2009, 10:52 AM
Hello,
I have a very simple static lib linking problem, g++ doesn't seem to find the static lib that I want to link, but I'm not too sure what I'm doing wrong. Its been a while since I developed in nix, and can't remember having this problem before. Any help would be appreciated..
Here are the three source files I am using...
staticlib.h
#ifndef STATICLIB_INCLUDE
#define STATICLIB_INCLUDE
int staticFunc( int );
#endif
staticlib.cpp
#include "staticlib.h"
int staticFunc( int val )
{
return ++val;
}
main.cpp
#include "staticlib.h"
#include <iostream>
int main( int argc, char** argv )
{
std::cout << "result = " << staticFunc(1) << '\n';
return 0;
}
so to compile staticlib.cpp....
g++ -c staticlib.cpp -o staticlib.o
ar -rv libstat.a staticlib.o
but then when I compile main.cpp, linking to the lib
g++ main.cpp -lstat -o main
/usr/bin/ld: cannot find -lstat
collect2: ld returned 1 exit status
Bit of a loss here...
Many thanks in Advance
I have a very simple static lib linking problem, g++ doesn't seem to find the static lib that I want to link, but I'm not too sure what I'm doing wrong. Its been a while since I developed in nix, and can't remember having this problem before. Any help would be appreciated..
Here are the three source files I am using...
staticlib.h
#ifndef STATICLIB_INCLUDE
#define STATICLIB_INCLUDE
int staticFunc( int );
#endif
staticlib.cpp
#include "staticlib.h"
int staticFunc( int val )
{
return ++val;
}
main.cpp
#include "staticlib.h"
#include <iostream>
int main( int argc, char** argv )
{
std::cout << "result = " << staticFunc(1) << '\n';
return 0;
}
so to compile staticlib.cpp....
g++ -c staticlib.cpp -o staticlib.o
ar -rv libstat.a staticlib.o
but then when I compile main.cpp, linking to the lib
g++ main.cpp -lstat -o main
/usr/bin/ld: cannot find -lstat
collect2: ld returned 1 exit status
Bit of a loss here...
Many thanks in Advance