Thread: problem creating .so

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    5

    problem creating .so

    Hi!

    In my project, I have to make a .so . In order to create the .so, I also need to compile some files:

    this is how the makefile looks like:

    CC = g++

    FLAGS_FPIC = -fPIC -m32 -I$(APP_INCL) -I$(CSI_INCL) -I$(MQ_INCL) -g

    (APP_INCL, CSI_INCL, MQ_INCL are paths to my .h files.)

    then, to create the .o files, i use:

    Bind.o: $(APP_SRC)/Bind.c
    $(CC) -c $(FLAGS_FPIC) $(APP_SRC)/Bind.c

    Init.o: $(APP_SRC)/Init.c
    $(CC) -c $(FLAGS_FPIC) $(APP_SRC)/Init.c

    .......


    to create the .so then, I use:

    FLAGS_SO_LIBS = -L$(CSI_LIB) \
    -lcsi_hlclient \
    -lcsi_report \
    -lm

    FLAGS_SO = -m32 -shared $(FLAGS_SO_LIBS) -lc -W1


    $(CC) $(FLAGS_SO),-soname,libZziCsiLib32.so.1 -o libZziCsiLib32.so.1.0.1 Bind.o Init.o Connect.o Put.o Get.o Disconnect.o Term.o


    When I try compiling, the compiler compiles the .c files, creates the .so, but when i try to compile the test class, where I use the library, it doesn't seem to see the functions, declared in the .h files , included to compile the .c files

    Any idea?

    Thanks, Rok

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    How are you linking your test app?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    5
    Hi!

    My testApp iz compiled like this:

    g++ -m32 SiEcnGetTest.o -L. -L/app/csi/lib -lcsi_hlclient -lcsi_report -lm -lc -lZziCsiLib32 -o SiEcnGetTest

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I take it you have
    Code:
    extern "C"
    around your headers?

    If you post (an example of if there are many) the error message(s) you get, we can probably help better.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Feb 2009
    Posts
    5
    g++ -m32 SiEcnGetTest.o -L. -L/app/csi/lib -lcsi_hlclient -lcsi_report -lm -lc -lZziCsiLib32 -o SiEcnGetTest
    --------------------------------------------------------------------------------------------------------------
    SiEcnGetTest.o: In function `main':
    SiEcnGetTest.c.text+0x295): undefined reference to `ccn_get'
    ./libZziCsiLib32.so: undefined reference to `HL_init_sec_context(tagCSISECINFO*, long*, long*)'
    ./libZziCsiLib32.so: undefined reference to `HL_bind(char*, char*, tagCSIQOS*, long*, long*)'
    ./libZziCsiLib32.so: undefined reference to `HL_decode(tagCSIDD*, long, char*, tagCSIDD*, long*, long*)'
    ./libZziCsiLib32.so: undefined reference to `HL_get_q_depth(long, long, long*, long*, long*)'
    ./libZziCsiLib32.so: undefined reference to `HL_mq_open(long, tagCSIMQOD*, long, long*, long*, long*)'
    ./libZziCsiLib32.so: undefined reference to `App_Init'
    ./libZziCsiLib32.so: undefined reference to `HL_encode(tagCSIDD*, char*, long, char*, tagCSIDD*, long*, long*)'
    ./libZziCsiLib32.so: undefined reference to `HL_alloc(unsigned long, tagCSIDD**, long*, long*)'
    ./libZziCsiLib32.so: undefined reference to `HL_free(tagCSIDD**, long*, long*)'
    ./libZziCsiLib32.so: undefined reference to `HL_mq_conn(char*, long*, long*, long*)'
    ./libZziCsiLib32.so: undefined reference to `HL_mq_browse(long, long, tagCSIMQMD*, tagCSIMQGMO*, tagCSIDD*, long*, tagCSIQOS*, long*, long*)'
    ./libZziCsiLib32.so: undefined reference to `App_Term'
    ./libZziCsiLib32.so: undefined reference to `HL_delete_sec_context(long*, long*)'
    ./libZziCsiLib32.so: undefined reference to `HL_mq_put(long, long, tagCSIMQMD*, tagCSIMQPMO*, tagCSIDD*, tagCSIQOS*, long*, long*)'
    ./libZziCsiLib32.so: undefined reference to `HL_unbind(long*, long*)'
    ./libZziCsiLib32.so: undefined reference to `HL_mq_disc(long*, long*, long*)'
    ./libZziCsiLib32.so: undefined reference to `App_Disconn'
    ./libZziCsiLib32.so: undefined reference to `App_PutMessage'
    ./libZziCsiLib32.so: undefined reference to `HL_mq_close(long, long*, long, long*, long*)'
    ./libZziCsiLib32.so: undefined reference to `HL_gettype(tagCSIDD*, char*, long*, char*, long*, long*)'
    collect2: ld returned 1 exit status

    is "extern C" that much of a big deal regarding this problem?

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'd say what you are seeing is directly an extern "C" problem - the reason I say that is that in C code functions, you never get a printout of the function arguments and return type - because the linker doesn't know that. In C++ compiled code, the basic function name is "decorated" with type information, so that for example
    Code:
    int blah(long a, int b)
    {
    }
    may result in a name like this:
    Code:
    i4$blah$l4i4
    It's probably not quite so obvious, but it's the principle of how it works.

    When you use extern "C", you tell the compiler "These functions are compiled as C rather than C++, so don't decorate them with C++ style return type and parameter information". [But in 10 characters]

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem creating tmp file in /var/tmp
    By Rahulds in forum Linux Programming
    Replies: 1
    Last Post: 03-14-2009, 01:57 AM
  2. Problem with Creating File for File Processing
    By Dampecram in forum C Programming
    Replies: 2
    Last Post: 12-07-2008, 01:26 AM
  3. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Replies: 3
    Last Post: 12-03-2001, 01:45 PM