link problem about X86_64

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

  1. danic84 macrumors newbie

    Nov 22, 2011
    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

    Apr 24, 2008
    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

    Nov 22, 2011
    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

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

    Nov 22, 2011
    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

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

    int testfunc(int a)
    	return a+1;
    #include <stdio.h>
    extern int testfunc(int a);
    	printf("%d\n", testfunc(1));
    Build and use:
    $ gcc -dynamiclib testlib.c -o testlib.dylib
    $ gcc -o testmain testmain.c testlib.dylib 
    $ ./testmain
    $ 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 6502a

    Madd the Sane

    Nov 8, 2010
    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