On MacOS 13.3 ld: symbol(s) not found for architecture xxx
mclaes42 opened this issue · 2 comments
mclaes42 commented
Hello,
I get a linker error when compiling the sample program.
I tried on
- Mac mini : Intel i5 : Ventura 13.3
- MacBook Pro : Apple M1 Pro : macOS Ventura 13.3
I have the same error on both. ld: symbols(s) not found for architecture xxx.
The prereq unixodbc and odbc-cpp-wrapper:
isql test_42
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| echo [string] |
| quit |
| |
+---------------------------------------+
SQL> quit
sudo make install
Password:
[ 41%] Built target odbccpp_static
[ 83%] Built target odbccpp
[100%] Built target OdbcCppTest
Install the project...
-- Install configuration: ""
-- Installing: /usr/local/lib/libodbccpp_static.a
-- Up-to-date: /usr/local/lib/libodbccpp.dylib
-- Up-to-date: /usr/local/include/odbc/Config.h
-- Up-to-date: /usr/local/include/odbc/Connection.h
-- Up-to-date: /usr/local/include/odbc/DatabaseMetaData.h
-- Up-to-date: /usr/local/include/odbc/DatabaseMetaDataBase.h
-- Up-to-date: /usr/local/include/odbc/DatabaseMetaDataUnicode.h
-- Up-to-date: /usr/local/include/odbc/Environment.h
-- Up-to-date: /usr/local/include/odbc/Exception.h
-- Up-to-date: /usr/local/include/odbc/Forwards.h
-- Up-to-date: /usr/local/include/odbc/ParameterMetaData.h
-- Up-to-date: /usr/local/include/odbc/PreparedStatement.h
-- Up-to-date: /usr/local/include/odbc/RefCounted.h
-- Up-to-date: /usr/local/include/odbc/ResultSet.h
-- Up-to-date: /usr/local/include/odbc/ResultSetMetaData.h
-- Up-to-date: /usr/local/include/odbc/ResultSetMetaDataBase.h
-- Up-to-date: /usr/local/include/odbc/ResultSetMetaDataUnicode.h
-- Up-to-date: /usr/local/include/odbc/Statement.h
-- Up-to-date: /usr/local/include/odbc/StatementBase.h
-- Up-to-date: /usr/local/include/odbc/StringConverter.h
-- Up-to-date: /usr/local/include/odbc/Types.h
-- Up-to-date: /usr/local/include/odbc/Util.h
The program taken from github
#include <iostream>
#include <odbc/Connection.h>
#include <odbc/Environment.h>
#include <odbc/Exception.h>
#include <odbc/PreparedStatement.h>
#include <odbc/ResultSet.h>
int main()
{
try
{
odbc::EnvironmentRef env = odbc::Environment::create();
odbc::ConnectionRef conn = env->createConnection();
conn->connect("DSN", "user", "pass");
conn->setAutoCommit(false);
odbc::PreparedStatementRef psInsert =
conn->prepareStatement("INSERT INTO TAB (ID, DATA) VALUES (?, ?)");
psInsert->setInt(1, 101);
psInsert->setCString(2, "One hundred one");
psInsert->addBatch();
psInsert->setInt(1, 102);
psInsert->setCString(2, "One hundred two");
psInsert->addBatch();
psInsert->executeBatch();
conn->commit();
odbc::PreparedStatementRef psSelect =
conn->prepareStatement("SELECT ID, DATA FROM TAB WHERE ID > ?");
psSelect->setInt(1, 100);
odbc::ResultSetRef rs = psSelect->executeQuery();
while (rs->next())
{
std::cout << rs->getInt(1) << ", " << rs->getString(2) << std::endl;
}
}
catch (const odbc::Exception& e)
{
std::cerr << e.what() << std::endl;
}
}
My issue
gcc -v -std=c++11 main.cpp
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: x86_64-apple-darwin22.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
"/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx13.0.0 -Wundef-prefix=TARGET_OS_ -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fno-strict-return -ffp-contract=on -fno-rounding-math -funwind-tables=2 -target-sdk-version=13.3 -fvisibility-inlines-hidden-static-local-var -target-cpu penryn -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=lldb -target-linker-version 857.1 -v -fcoverage-compilation-dir=/Users/michel/src/test_odbc/test_odbc -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/14.0.3 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -stdlib=libc++ -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1 -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Library/Developer/CommandLineTools/usr/lib/clang/14.0.3/include -internal-externc-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Library/Developer/CommandLineTools/usr/include -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -Wno-elaborated-enum-base -Wno-reserved-identifier -Wno-gnu-folding-constant -std=c++11 -fdeprecated-macro -fdebug-compilation-dir=/Users/michel/src/test_odbc/test_odbc -ferror-limit 19 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fno-cxx-modules -no-opaque-pointers -fcxx-exceptions -fexceptions -fmax-type-align=16 -fcommon -fcolor-diagnostics -clang-vendor-feature=+disableNonDependentMemberExprInCurrentInstantiation -fno-odr-hash-protocols -clang-vendor-feature=+enableAggressiveVLAFolding -clang-vendor-feature=+revert09abecef7bbf -clang-vendor-feature=+thisNoAlignAttr -clang-vendor-feature=+thisNoNullAttr -mllvm -disable-aligned-alloc-awareness=1 -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/dw/9qv77fv97rg6ww8y9r2d029c0000gn/T/main-a6c492.o -x c++ main.cpp
clang -cc1 version 14.0.3 (clang-1403.0.22.14.1) default target x86_64-apple-darwin22.4.0
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1
/Library/Developer/CommandLineTools/usr/lib/clang/14.0.3/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
/Library/Developer/CommandLineTools/usr/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
"/Library/Developer/CommandLineTools/usr/bin/ld" -demangle -lto_library /Library/Developer/CommandLineTools/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -platform_version macos 13.0.0 13.3 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -o a.out -L/usr/local/lib /var/folders/dw/9qv77fv97rg6ww8y9r2d029c0000gn/T/main-a6c492.o -lSystem /Library/Developer/CommandLineTools/usr/lib/clang/14.0.3/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"odbc::Connection::setAutoCommit(bool)", referenced from:
_main in main-a6c492.o
"odbc::Connection::prepareStatement(char const*)", referenced from:
_main in main-a6c492.o
"odbc::Connection::commit()", referenced from:
_main in main-a6c492.o
"odbc::Connection::connect(char const*, char const*, char const*)", referenced from:
_main in main-a6c492.o
"odbc::Environment::createConnection()", referenced from:
_main in main-a6c492.o
"odbc::Environment::create()", referenced from:
_main in main-a6c492.o
"odbc::PreparedStatement::setCString(unsigned short, char const*)", referenced from:
_main in main-a6c492.o
"odbc::PreparedStatement::executeBatch()", referenced from:
_main in main-a6c492.o
"odbc::PreparedStatement::executeQuery()", referenced from:
_main in main-a6c492.o
"odbc::PreparedStatement::setInt(unsigned short, odbc::Nullable<int> const&)", referenced from:
_main in main-a6c492.o
"odbc::PreparedStatement::addBatch()", referenced from:
_main in main-a6c492.o
"odbc::ResultSet::next()", referenced from:
_main in main-a6c492.o
"odbc::ResultSet::getInt(unsigned short)", referenced from:
_main in main-a6c492.o
"odbc::ResultSet::getString(unsigned short)", referenced from:
_main in main-a6c492.o
"odbc::RefCounted::decRef() const", referenced from:
odbc::Reference<odbc::Environment>::free_() in main-a6c492.o
odbc::Reference<odbc::Connection>::free_() in main-a6c492.o
odbc::Reference<odbc::PreparedStatement>::free_() in main-a6c492.o
odbc::Reference<odbc::ResultSet>::free_() in main-a6c492.o
"std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from:
std::__1::ctype<char> const& std::__1::use_facet[abi:v15006]<std::__1::ctype<char>>(std::__1::locale const&) in main-a6c492.o
"std::__1::ios_base::getloc() const", referenced from:
std::__1::basic_ios<char, std::__1::char_traits<char>>::widen[abi:v15006](char) const in main-a6c492.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::__init(unsigned long, char)", referenced from:
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::basic_string[abi:v15006](unsigned long, char) in main-a6c492.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::~basic_string()", referenced from:
odbc::Nullable<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>::~Nullable() in main-a6c492.o
std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>> std::__1::__pad_and_output<char, std::__1::char_traits<char>>(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>>, char const*, char const*, char const*, std::__1::ios_base&, char) in main-a6c492.o
"std::__1::basic_ostream<char, std::__1::char_traits<char>>::put(char)", referenced from:
std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::endl<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&) in main-a6c492.o
"std::__1::basic_ostream<char, std::__1::char_traits<char>>::flush()", referenced from:
std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::endl<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&) in main-a6c492.o
"std::__1::basic_ostream<char, std::__1::char_traits<char>>::sentry::sentry(std::__1::basic_ostream<char, std::__1::char_traits<char>>&)", referenced from:
std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::__put_character_sequence<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, char const*, unsigned long) in main-a6c492.o
"std::__1::basic_ostream<char, std::__1::char_traits<char>>::sentry::~sentry()", referenced from:
std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::__put_character_sequence<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, char const*, unsigned long) in main-a6c492.o
"std::__1::basic_ostream<char, std::__1::char_traits<char>>::operator<<(int)", referenced from:
std::__1::basic_ostream<char, std::__1::char_traits<char>>& odbc::operator<<<int>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, odbc::Nullable<int> const&) in main-a6c492.o
"std::__1::cerr", referenced from:
_main in main-a6c492.o
"std::__1::cout", referenced from:
_main in main-a6c492.o
"std::__1::ctype<char>::id", referenced from:
std::__1::ctype<char> const& std::__1::use_facet[abi:v15006]<std::__1::ctype<char>>(std::__1::locale const&) in main-a6c492.o
"std::__1::locale::~locale()", referenced from:
std::__1::basic_ios<char, std::__1::char_traits<char>>::widen[abi:v15006](char) const in main-a6c492.o
"std::__1::ios_base::__set_badbit_and_consider_rethrow()", referenced from:
std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::__put_character_sequence<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, char const*, unsigned long) in main-a6c492.o
"std::__1::ios_base::clear(unsigned int)", referenced from:
std::__1::ios_base::setstate[abi:v15006](unsigned int) in main-a6c492.o
"std::terminate()", referenced from:
___clang_call_terminate in main-a6c492.o
"typeinfo for odbc::Exception", referenced from:
GCC_except_table0 in main-a6c492.o
"___cxa_begin_catch", referenced from:
_main in main-a6c492.o
___clang_call_terminate in main-a6c492.o
std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::__put_character_sequence<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, char const*, unsigned long) in main-a6c492.o
"___cxa_end_catch", referenced from:
_main in main-a6c492.o
std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::__put_character_sequence<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, char const*, unsigned long) in main-a6c492.o
"___gxx_personality_v0", referenced from:
_main in main-a6c492.o
std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::__put_character_sequence<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, char const*, unsigned long) in main-a6c492.o
std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>> std::__1::__pad_and_output<char, std::__1::char_traits<char>>(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>>, char const*, char const*, char const*, std::__1::ios_base&, char) in main-a6c492.o
std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>>::ostreambuf_iterator[abi:v15006](std::__1::basic_ostream<char, std::__1::char_traits<char>>&) in main-a6c492.o
std::__1::basic_ios<char, std::__1::char_traits<char>>::widen[abi:v15006](char) const in main-a6c492.o
odbc::Reference<odbc::Environment>::~Reference() in main-a6c492.o
odbc::Reference<odbc::Connection>::~Reference() in main-a6c492.o
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Adding path to unixodbc lib doesn't help
gcc -v -std=c++11 -L/usr/local/Cellar/unixodbc/2.3.11/lib main.cpp
...
ld: symbol(s) not found for architecture x86_64
Thanks in advance for your help
stefanuhrig commented
You have to specify the name of the library:
g++ -lodbccpp main.cpp
This works at least for Linux, but I guess it's the same or similar on MacOS.
stefanuhrig commented
Closing as there was no more feedback.