Mac link problem about X86_64

danic84

macrumors newbie
Original poster
Nov 22, 2011
3
0
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
 

Sander

macrumors 6502
Apr 24, 2008
480
7
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.
 

danic84

macrumors newbie
Original poster
Nov 22, 2011
3
0
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.
Thank you for answer.
I don't have a main() because i'm creating a swig module that doesn't provide for main function.
 

danic84

macrumors newbie
Original poster
Nov 22, 2011
3
0
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
 

mfram

macrumors 65816
Jan 23, 2010
1,064
142
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:

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.
 

Madd the Sane

macrumors 6502a
Nov 8, 2010
508
40
Utah
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.