[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Creating and sharing a c++ shared library ?
From: |
Markus Kossmann |
Subject: |
Re: Creating and sharing a c++ shared library ? |
Date: |
Sun, 25 Feb 2007 20:49:57 +0100 |
User-agent: |
KNode/0.10.4 |
vivekian wrote:
> 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 ?
The linker looks only for .so and .a files ( without any version number)
Create a link libcppsocket.so -> libcppsocket.so.1.0.1.