[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Creating and sharing a c++ shared library ?
From: |
vivekian |
Subject: |
Creating and sharing a c++ shared library ? |
Date: |
25 Feb 2007 11:16:34 -0800 |
User-agent: |
G2/1.0 |
Hi ,
These are the steps i followed to create a shared library
1. Compiled the cpp files
g++ -c -g -fpic -Wall -Wno-deprecated SockException.cpp -o
SockException.o
g++ -c -g -fpic -Wall -Wno-deprecated Socket.cpp -o Socket.o
g++ -c -g -fpic -Wall -Wno-deprecated TcpSocket.cpp -o TcpSocket.o
g++ -c -g -fpic -Wall -Wno-deprecated UdpSocket.cpp -o UdpSocket.o
g++ -c -g -fpic -Wall -Wno-deprecated SocketReaderWriter.cpp -o
SocketReaderWriter.o
g++ -shared -Wl,-soname,libcppsocket.so.1 -o libcppsocket.so.1.0.1
SockException.o Socket.o TcpSocket.o UdpSocket.o SocketReaderWriter.o -
lc
2. Copied the compiled libcppsocket.so.1 to the directories /usr/lib
3. Moved the header files to the directories /usr/include and /usr/
local/include
4. To test the compiled library , i wrote a small program
#include <TcpSocket.h>
int main ()
{
TcpSocket sock ;
}
where TcpSocket.h is one of the header files copied to /usr/include
5. Compiling this test program
g++ main.cpp
/tmp/ccPqeVa9.o: In function `main':
main.cpp:(.text+0x8a): undefined reference to `TcpSocket::TcpSocket()'
main.cpp:(.text+0x95): undefined reference to
`TcpSocket::~TcpSocket()'
collect2: ld returned 1 exit status
gives the above error.
This i suppose indicates that the library has to be linked. But the
following doesnt help
g++ main.cpp -llibcppsocket
What am i missing here ?
Thanks in advance,
vivekian
- Creating and sharing a c++ shared library ?,
vivekian <=