我实际上正在将 Linux 应用程序移植到 Mac OS X。我的问题是我可以访问变量但不能访问指针。
我以这种方式声明了变量main.h
:
uint64_t test;
uint64_t *test2;
在mylib.h
:
extern uint64_t test;
extern uint64_t *test2;
在mylib.c
我以这种方式访问变量:
printf("%llu\n",test);
printf("%llu\n",*test2);
第一个printf()
没有任何问题,但第二个给了我这个错误:
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000008
有人知道为什么会这样吗?
我的ggc
命令行具有以下标志:
gcc -Wall -g -fPIC -c main.c gcc -shared -Wl,-undefined,dynamic_lookup -o mylib.so mylib.o