我想在OS X上编译一个简单的Oracle应用程序并运行到链接问题。任何帮助,将不胜感激。在OSX上构建Oracle Instant Client链接错误
#include <iostream>
#include <occi.h>
using namespace std;
using namespace oracle::occi;
Environment * env;
Connection * conn;
int main(int argc, char ** argv)
{
env = Environment::createEnvironment(Environment::OBJECT);
conn = env->createConnection("scott", "tiger", "//lcoalhost:1521/xe");
Statement *stmt = conn->createStatement("SELECT COUNT(*) FROM TAB");
ResultSet *rs=stmt->executeQuery();
rs->next();
string ntabs=rs->getString(1);
cout << "Number of tables " << ntabs << endl;
conn->terminateStatement(stmt);
// Close connection etc
env->terminateConnection(conn);
Environment::terminateEnvironment(env);
return 0;
}
我有安装在~/oracle_client
的x64 oracle即时客户端。我可以使用sqlplus
和python (cx_Oracle)
连接到数据库。
我编译文件使用以下命令
gcc main.cpp -I ~/oracle_client/sdk/include/ -L ~/oracle_client -locci -lclntsh
下面是ld
错误我收到:
ld: warning: ignoring file <ORACLE_HOME >/libclntsh.dylib, file was built for unsupported file format (0x62 0x6f 0x6f 0x6b 0x 0 0x 0 0x 0 0x 0 0x6d 0x61 0x72 0x6b 0x 0 0x 0 0x 0 0x 0) which is not the architecture being linked (x86_64): <ORACLE_HOME>/libclntsh.dylib
Undefined symbols for architecture x86_64:
"std::allocator::allocator()", referenced from:
_main in ccWf4dno.o
"std::allocator::~allocator()", referenced from:
_main in ccWf4dno.o
"std::basic_ostream >::operator >& (*)(std::basic_ostream >&))", referenced from:
_main in ccWf4dno.o
"std::basic_string, std::allocator >::basic_string(char const*, std::allocator const&)", referenced from:
_main in ccWf4dno.o
"std::basic_string, std::allocator >::~basic_string()", referenced from:
_main in ccWf4dno.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in ccWf4dno.o
"std::ios_base::Init::~Init()", referenced from:
___tcf_0 in ccWf4dno.o
"std::cout", referenced from:
_main in ccWf4dno.o
"std::basic_ostream >& std::endl >(std::basic_ostream >&)", referenced from:
_main in ccWf4dno.o
"std::terminate()", referenced from:
_main in ccWf4dno.o
"std::basic_ostream >& std::operator >(std::basic_ostream >&, char const*)", referenced from:
_main in ccWf4dno.o
"std::basic_ostream >& std::operator, std::allocator >(std::basic_ostream >&, std::basic_string, std::allocator > const&)", referenced from:
_main in ccWf4dno.o
"___gxx_personality_v0", referenced from:
Dwarf Exception Unwind Info (__eh_frame) in ccWf4dno.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
即时客户端具有不同的32位和64位版本,它们不包含两者。用'-m32'或'-m64'避免了这个问题,只剩下那些错误。你说得很对,用'g ++'确实解决了这个问题 - 但你需要两个。 – 2013-02-26 23:24:30