link problem about X86_64

Discussion in 'Mac Programming' started by danic84, Nov 22, 2011.

  1. danic84 macrumors newbie

    Joined:
    Nov 22, 2011
    #1
    i'm working with FFMPEG on MAC OSX, my MAC version is 10.6.8 (i386).

    When i try to compile my c++ code linking a dynamic library:

    g++ sdk.cpp -rpath /usr/local/lib/libinsight.dylib -o sdk

    i get back the following error:

    Undefined symbols for architecture x86_64:
    "_main", referenced from:
    start in crt1.10.6.o
    "av_open_input_file(AVFormatContext**, char const*, AVInputFormat*, int, AVFormatParameters*)", referenced from:
    ffmpeg_open(AVFormatContext**, char const*, int*)in ccCkx9dd.o

    (so forth fo every FFMPEG call)

    ld: symbol(s) not found for architecture x86_64
    collect2: ld returned 1 exit status

    Without linking dylib i have no problem. What's the matter? Thanks in advance...

    ps: ffmpeg version is Mach-O 64-bit executable x86_64
     
  2. Sander macrumors 6502

    Joined:
    Apr 24, 2008
    #2
    You have to specify that you're building a library, as the default for gcc is an executable. It is looking for your main() function and can't find it.
     
  3. danic84 thread starter macrumors newbie

    Joined:
    Nov 22, 2011
    #3
    Thank you for answer.
    I don't have a main() because i'm creating a swig module that doesn't provide for main function.
     
  4. mfram macrumors 65816

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
  5. danic84 thread starter macrumors newbie

    Joined:
    Nov 22, 2011
    #5
    If i add -c flag the linker doesn't run, actually the command gets back:

    i686-apple-darwin10-llvm-g++-4.2: /usr/local/lib/libinsight.dylib: linker input file unused because linking not done
     
  6. mfram macrumors 65816

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #6
    Sorry, missed the part about you wanting a dynamic library. Studying the gcc man page and playing around, I came up with this:

    testlib.c
    Code:
    int testfunc(int a)
    {
    	return a+1;
    }
    
    testmain.c
    Code:
    #include <stdio.h>
    
    extern int testfunc(int a);
    
    main()
    {
    	printf("%d\n", testfunc(1));
    }
    
    Build and use:
    Code:
    $ gcc -dynamiclib testlib.c -o testlib.dylib
    $ gcc -o testmain testmain.c testlib.dylib 
    $ ./testmain
    2
    $ file testmain testlib.dylib 
    testmain:      Mach-O 64-bit executable x86_64
    testlib.dylib: Mach-O 64-bit dynamically linked shared library x86_64
    

    if you want multiple source files in the dynamic library, then compile each with the '-c' argument and put all of the .o files into the command with the -dynamiclib argument.
     
  7. Madd the Sane macrumors 6502

    Madd the Sane

    Joined:
    Nov 8, 2010
    Location:
    Utah
    #7
    Wirelessly posted (Mozilla/5.0 (iPod; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3)

    Just my 2¢: most plugins are actually defined with the -bundle linker flag on Mac OS X. The thing about bundles, though, is they can't be linked against. So if you write a program that uses a function in a bundle, you have to load it at runtime in code.
     

Share This Page