Thread: How to rebuild a library?

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    78

    How to rebuild a library?

    Hi again!


    I would like to build upon one of my previous threads (Link), where the original problem has changed to a new one.

    I'm referring to the following lines of code:

    Code:
    mpi_kmeans_mex.$(SUFFIX):    libmpikmeans mpi_kmeans_mex.o 
        $(CC) mpi_kmeans_mex.o -shared -o mpi_kmeans_mex.$(SUFFIX) libmpikmeans.a $(MATLAB_LIB) 
    
    mpi_assign_mex.$(SUFFIX):    libmpikmeans mpi_assign_mex.o
        $(CC) mpi_assign_mex.o -shared -o mpi_assign_mex.$(SUFFIX) libmpikmeans.a $(MATLAB_LIB)
    My code is unable to run, since the existing library libmpikmeans.a and object file mpi_assign_mex.o (Linux) are not compatible with my system (Mac). Thus, they must be rebuilt-

    I've found a similar thread here, but I'm not sure how and where to implement this.
    Additionally, how do I rebuild .o files?


    Any suggestions?
    Last edited by in_ship; 09-17-2012 at 02:19 PM.

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    you need to get the source for the library and rebuild on your machine. for that library i googled 'mpikmeans' and found this link for the project mloss | Project details:MPIKmeans. there is a link title 'Archive: download here' that lets you download the source. then you have to use your Mac tools to build it according to instructions in the README and Makefile files.

  3. #3
    Registered User
    Join Date
    Aug 2012
    Posts
    78
    Quote Originally Posted by dmh2000 View Post
    you need to get the source for the library and rebuild on your machine. for that library i googled 'mpikmeans' and found this link for the project mloss | Project details:MPIKmeans. there is a link title 'Archive: download here' that lets you download the source. then you have to use your Mac tools to build it according to instructions in the README and Makefile files.
    Hey dmh2000!

    Thanks for your effort!
    I have the file already. The code excerpt I've posted above was from the makefile itself!
    Let me post another part of the Makefile. This is where the library (.a) and object files (.o) are created (I think!)

    Code:
    #
    # Choose your compiler
    #
    
    CC = gcc
    CPP = g++
    CFLAGS=-O3 -ffast-math -fomit-frame-pointer -fPIC -Werror 
    
    #
    # MPI KMEANS FLAGS
    #
    VERBOSEFLAG=-DKMEANS_VERBOSE=0 # 0: silent, 1:iteration counter, 2:everything
    PRECISION=-DINPUT_TYPE=0 # 0: double, 1:float 
    
    
    matlab: mpi_kmeans_mex.$(SUFFIX) mpi_assign_mex.$(SUFFIX)
    
    standalone:    mpi_kmeans_main mpi_assign_main
    python:    cython_wrapper
    
    mpi_kmeans.o:    mpi_kmeans.cxx mpi_kmeans.h
        $(CC) $(CFLAGS) $(VERBOSEFLAG) $(PRECISION) -c -o $@ mpi_kmeans.cxx
    
    libmpikmeans:    mpi_kmeans.o
        ar rc libmpikmeans.a mpi_kmeans.o
        ranlib libmpikmeans.a
        $(CPP) -shared -fPIC $(CFLAGS) $(VERBOSEFLAG) -o libmpikmeans.so $(VERBOSEFLAGS) $(PRECISION) mpi_kmeans.cxx
    
    mpi_kmeans_main.o:    mpi_kmeans_main.cxx
        $(CC) $(CFLAGS) $(VERBOSEFLAG) $(BOOST_INCLUDE) -c -o mpi_kmeans_main.o mpi_kmeans_main.cxx 
    
    mpi_assign_main.o:    mpi_assign_main.cxx
        $(CC) $(CFLAGS) $(VERBOSEFLAG) $(BOOST_INCLUDE) -c -o mpi_assign_main.o mpi_assign_main.cxx 
    
    mpi_kmeans_main:    libmpikmeans mpi_kmeans_main.o
        $(CC) mpi_kmeans_main.o  $(CFLAGS) $(VERBOSEFLAG) -L/usr/lib/ -static -o mpi_kmeans -lm libmpikmeans.a \
            $(BOOST_LIB) $(LIBS)
    
    mpi_assign_main:    libmpikmeans mpi_assign_main.o
        $(CC) mpi_assign_main.o $(CFLAGS) $(VERBOSEFLAG) -L/usr/lib/ -static -o mpi_assign -lm libmpikmeans.a \
            $(BOOST_LIB) $(LIBS)
    
    %_mex.o:    %_mex.cxx
        $(CC) $(CFLAGS) $(VERBOSEFLAG) $(MATLAB_INCLUDE) $(PRECISION) -c $^ -o $@
    
    #
    # These are the two main files we need !!
    #
    mpi_kmeans_mex.$(SUFFIX):    libmpikmeans mpi_kmeans_mex.o 
        $(CC) mpi_kmeans_mex.o -shared -o mpi_kmeans_mex.$(SUFFIX) libmpikmeans.a $(MATLAB_LIB) 
    
    mpi_assign_mex.$(SUFFIX):    libmpikmeans mpi_assign_mex.o
        $(CC) mpi_assign_mex.o -shared -o mpi_assign_mex.$(SUFFIX) libmpikmeans.a $(MATLAB_LIB)
    #
    # end
    #
    In the readme file, it says: run make matlab. I've highlighted the parts I BELIEVE are carried out, once I use the command.
    Now which line am I supposed to modify - and how?
    Last edited by in_ship; 09-18-2012 at 12:34 PM.

  4. #4
    Registered User
    Join Date
    Aug 2012
    Posts
    78
    Interesting update

    I deleted all the .o and .a (library) file in the folder, ran make matlab again and the version incompatibility error vanished.

    Instead - I'm still getting a few random errors:

    gcc -O3 -ffast-math -fomit-frame-pointer -fPIC -Werror -m64 -DKMEANS_VERBOSE=0 -DINPUT_TYPE=0 -c -o mpi_kmeans.o mpi_kmeans.cxx
    ar rc libmpikmeans.a mpi_kmeans.o
    ranlib libmpikmeans.a
    g++ -shared -fPIC -O3 -ffast-math -fomit-frame-pointer -fPIC -Werror -m64 -DKMEANS_VERBOSE=0 -o libmpikmeans.so -DINPUT_TYPE=0 mpi_kmeans.cxx
    gcc -O3 -ffast-math -fomit-frame-pointer -fPIC -Werror -m64 -DKMEANS_VERBOSE=0 -I/Applications/MATLAB_R2011a.app/extern/include -DINPUT_TYPE=0 -c mpi_kmeans_mex.cxx -o mpi_kmeans_mex.o
    g++ mpi_kmeans_mex.o -shared -o mpi_kmeans_mex.mexmaci64 libmpikmeans.a -L/Applications/MATLAB_R2011a.app/bin/maci64 -lmex
    Undefined symbols:
    "_mxGetM", referenced from:
    _mexFunction in mpi_kmeans_mex.o
    _mexFunction in mpi_kmeans_mex.o
    _mexFunction in mpi_kmeans_mex.o
    _mexFunction in mpi_kmeans_mex.o
    _mexFunction in mpi_kmeans_mex.o
    "_mxGetN", referenced from:
    _mexFunction in mpi_kmeans_mex.o
    _mexFunction in mpi_kmeans_mex.o
    _mexFunction in mpi_kmeans_mex.o
    _mexFunction in mpi_kmeans_mex.o
    _mexFunction in mpi_kmeans_mex.o

    ... more errors ....
    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    make: *** [mpi_kmeans_mex.mexmaci64] Error 1
    What's going on here in mpi_kmeans_mex.o?

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    _mexFunction and others are likely defined in libmex.so (or .a). Are you sure to have that binary? (and in the correct format)

  6. #6
    Registered User
    Join Date
    Aug 2012
    Posts
    78
    I deleted the original files libmpikmeans.a and libmpikmeans.so and the incompatibility error vanished.
    Once I run the makefile given above both files are generated anew - presumably in the right format too.

    If not - what would you suggest doing?

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    Yes, those object files are indeed compiled properly, but according to your logs, the linker cannot resolve external symbols for the final step.
    I guess it's because the "mex" library (due to -lmex on the command line) is probably missing;
    so I'm just asking if you do have that file (libmex.so) in the directory you specified (../maci64).

  8. #8
    Registered User
    Join Date
    Aug 2012
    Posts
    78
    Quote Originally Posted by root4 View Post
    Yes, those object files are indeed compiled properly, but according to your logs, the linker cannot resolve external symbols for the final step.
    I guess it's because the "mex" library (due to -lmex on the command line) is probably missing;
    so I'm just asking if you do have that file (libmex.so) in the directory you specified (../maci64).
    Aha - I see what you mean now.
    You're right - the file libmex.so does NOT exist in the path /Applications/MATLAB_R2011a.app/bin/maci64
    However, there is a file called libmex.dylib instead - isn't that good enough?
    Last edited by in_ship; 09-19-2012 at 02:51 AM.

  9. #9
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    Yes, it's indeed .dylib on OSX, so that should be fine. I don't understand what's missing :/
    Try to check that the missing symbols are indeed in that binary ($ nm libmex.dylib | grep _mexFunction).

  10. #10
    Registered User
    Join Date
    Aug 2012
    Posts
    78
    Quote Originally Posted by root4 View Post
    Yes, it's indeed .dylib on OSX, so that should be fine. I don't understand what's missing :/
    Try to check that the missing symbols are indeed in that binary ($ nm libmex.dylib | grep _mexFunction).
    I received the following reply:

    Code:
    docking-etx-40-155-dhcp:maci64 username$ nm libmex.dylib | grep _mexFunction
    0000000000001bd0 T _mexFunctionName
    Is that alright?

  11. #11
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    I would say no, as you see it's not the same symbol.

    If you're still struggling with this problem, I suggest you ask directly to the package maintainer or someone experienced with matlab programming.
    I don't have matlab myself so my options here are pretty limited...

  12. #12
    Registered User
    Join Date
    Aug 2012
    Posts
    78
    Quote Originally Posted by root4 View Post
    I would say no, as you see it's not the same symbol.

    If you're still struggling with this problem, I suggest you ask directly to the package maintainer or someone experienced with matlab programming.
    I don't have matlab myself so my options here are pretty limited...

    Ok - thanks for your help anyhow.
    I switched to Linux and managed to run my code using the precompiled mex files. No trouble with Mac anymore.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-08-2012, 10:23 PM
  2. Static library vs Dynamic library
    By Alegomaster in forum C Programming
    Replies: 5
    Last Post: 03-17-2011, 07:26 PM
  3. Replies: 19
    Last Post: 01-12-2006, 11:04 AM
  4. How to rebuild class view data
    By VirtualAce in forum Windows Programming
    Replies: 2
    Last Post: 03-22-2005, 01:28 PM
  5. XML library
    By Massive in forum C Programming
    Replies: 9
    Last Post: 07-04-2003, 07:14 AM