我想在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