编译JVMTI代理(在OSX Snow Leopard上使用GCC) [英] Compiling JVMTI agent (using GCC, on OSX Snow Leopard)
问题描述
我试图在Snow Leopard上使用g ++命令来构建JVMTI代理,并且出现以下错误:
I am trying to build a JVMTI agent using the g++ command on Snow Leopard and I get the following error:
$ g++ -o agent.so -I `/usr/libexec/java_home`/include agent.cpp
Undefined symbols: "_main", referenced from: start in crt1.10.6.o ld:
symbol(s) not found collect2: ld returned 1 exit status
当谈到gcc和C ++编程时,我是个新手,所以我不知道这个错误的含义。代理本身是非常基本的:
I am a total novice when it comes to gcc and C++ programming so I have no idea what that error means. The agent itself is extremely basic:
#include
#include
JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
{
std::cout <<"Loading aspect..." <<std::endl;
return JNI_OK;
}
任何有关该消息的帮助都将不胜感激。
Any help with the message would be greatly appreciated.
推荐答案
你提供给g ++的命令行选项告诉它你正在尝试构建一个可执行文件,而不是共享库。 g ++抱怨你没有定义 main
函数,因为每个可执行文件都需要一个。
The command line options you've supplied to g++ are telling it that you're trying to build an executable, not a shared library. g++ is complaining that you haven't defined a main
function, as every executable requires one.
编译共享带-c标志的库,以便g ++知道要建立一个库,即编译和组装你的代码,但不要试图将它链接到一个可执行文件中。
Compile your shared library with the -c flag so that g++ knows to build a library, i.e. compile and assemble your code, but don't try to link it into an executable file.
g++ -c -o agent.so -I `/usr/libexec/java_home`/include agent.cpp
这篇关于编译JVMTI代理(在OSX Snow Leopard上使用GCC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!