I'm actually porting a Linux app to Mac OS X. My problem is that I can access the variables but not the pointers.
I declared the variables in the main.h
this way:
uint64_t test;
uint64_t *test2;
In the mylib.h
:
extern uint64_t test;
extern uint64_t *test2;
and in mylib.c
I access the variables this way:
printf("%llu\n",test);
printf("%llu\n",*test2);
The first printf()
doesn't have any problems but the second gives me this error:
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000008
Does anybody know why this happened?
My ggc
command line has the following flags:
gcc -Wall -g -fPIC -c main.c gcc -shared -Wl,-undefined,dynamic_lookup -o mylib.so mylib.o