Shared Library problem

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
martinrame
Posts: 347
Joined: Mon, 2009-02-23, 19:57

Shared Library problem

#1 Post by martinrame »

Hi, I'm trying to create a shared object library to use in my FreePascal programs, but I get this error when I call dlopen to my library:

Code: Select all

libtest.so: undefined symbol: _ZN9log4cplus6Logger11addAppenderENS_7helpers15SharedObjectPtrINS_8AppenderEEE
This is what I did to create the library:

1) Go to the top directory of dcmtk sources.
cd ~/Desarrollo/dcmtk/dcmtk-3.5.5_20100504

2) Clean all before adding -fPIC to the CXXFLAGS.
make clean

3) cd config
4) Modify Makefile.def to add -fPIC to CFLAGS and CXXFLAGS
5) Back to the top dcmtk directory and make all.
cd .. && make
6) My library is based on the Multi-Frame example from the HowTo: http://support.dcmtk.org/wiki/dcmtk/howto/multiframe

Code: Select all

#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmimgle/dcmimage.h"

int NumFrames(char * filename){
    //OFLog::configure(OFLogger::INFO_LOG_LEVEL);
    DicomImage *image = new DicomImage(filename, CIF_UsePartialAccessToPixelData, 0, 10 /* fcount */); 
    if (image->getStatus() == EIS_Normal)
    {
        do {
            DCMIMGLE_INFO("processing frame " << image->getFirstFrame() + 1 << " to "
                                              << image->getFirstFrame() + image->getFrameCount());
        } while (image->processNextFrames());
    }
    delete image;
    return 0;
}
 
extern "C" {
  int GetNumFrames(char * filename) {
    return NumFrames(filename);
  }
}
7) As the library doesn't have an "int main", I added -c flag to the Makefile,
also added the -fPIC flag, and did a "make" to compile it.

8) After this, I got test.o, now I create a .so file with this:
g++ -shared -o libtest.so test.o

9) That's all, now, when I try to load the library I get the error mentioned at the beginning.

What am I doing wrong?.

P.S.: I'm using Ubuntu 10.04 64bits.

Thanks in advance,
Leonardo.

martinrame
Posts: 347
Joined: Mon, 2009-02-23, 19:57

#2 Post by martinrame »

Any hint?

martinrame
Posts: 347
Joined: Mon, 2009-02-23, 19:57

#3 Post by martinrame »

I found the solution.

Instead of linking with this:

Code: Select all

g++ -shared -o libtest.so test.o 
It's mandatory to include all the .o files needed by the shared library:

Code: Select all

g++ -pthread -shared -o libtest.so test.o ../../oflog/libsrc/*.o ../../ofstd/libsrc/oflist.o ../../ofstd/libsrc/ofstring.o ../../ofstd/libsrc/ofstd.o ../../ofstd/libsrc/ofcond.o ../../ofstd/libsrc/ofthread.o ../../dcmimage/libsrc/*.o ../../dcmimgle/libsrc/*.o ../../dcmdata/libsrc/*.o

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest