xcode c++ sqlite3 symbol(s) not found for architecture x86_64 - c++

Hi I want to use sqlite in c++ project in xcode 4
now i am getting this error
Ld /Users/jayb/Library/Developer/Xcode/DerivedData/EMS-bpigynlzjbrescadebhoiupqmtkg/Build/Products/Debug/EMS normal x86_64
cd /Users/jayb/Documents/Developement/EMS/EMS
setenv MACOSX_DEPLOYMENT_TARGET 10.8
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/jayb/Library/Developer/Xcode/DerivedData/EMS-bpigynlzjbrescadebhoiupqmtkg/Build/Products/Debug -F/Users/jayb/Library/Developer/Xcode/DerivedData/EMS-bpigynlzjbrescadebhoiupqmtkg/Build/Products/Debug -filelist /Users/jayb/Library/Developer/Xcode/DerivedData/EMS-bpigynlzjbrescadebhoiupqmtkg/Build/Intermediates/EMS.build/Debug/EMS.build/Objects-normal/x86_64/EMS.LinkFileList -mmacosx-version-min=10.8 -o /Users/jayb/Library/Developer/Xcode/DerivedData/EMS-bpigynlzjbrescadebhoiupqmtkg/Build/Products/Debug/EMS
Undefined symbols for architecture x86_64:
"_sqlite3_close", referenced from:
_main in main.o
"_sqlite3_errmsg", referenced from:
_main in main.o
"_sqlite3_open", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
and i found that is linker problem
it may fix with compiler option -lsqlite3
but, how can i add that option in Xcode??????
I use "Run" button on xcode 4.4 to compile my project.
i am not compiling in terminal window.
this is my code
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <sqlite3.h>
using namespace std;
int main()
{
sqlite3 *db;
int rc = sqlite3_open("EMSDB", &db);
if (rc) {
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
exit(0);
}
else {
fprintf(stderr, "Opened Database successfully\n");
}
sqlite3_close(db);
return 0;
}

I found the way,
wish it helps someone looking for the same solution.
now it builds correct and i can see the output
woops, I cannot post image yet :(
from the xcode build settings,
you can find a tab called (Linking)
and on the Linking tab
there are field call 'Other Linker Flags'
i simply added the -lsqlite3 for both Debug, and Release
cheers

I was getting the similar error : I did following in my case:
#import <sqlite3.h>

I am not familiar with xcode. Look for linker settings or compiler settings and add the -lsqlite3 there.
Perhaps this page helps: Xcode what's the difference between "Other Linker Flags" vs "Other_LDFLAGS"
LDFLAGS are passed to the linker. CFLAGS are passed to the compiler.

It is require to link libsqlite3.dylib in your project. That can be done in
Linked Frameworks and Libraries and add libsqlite3.dylib.
for reference follow:
xcode sqlite3 libsqlite.dylib

Related

How to use the fmt library without getting "Undefined symbols for architecture x86_64"

I'm trying to use the fmt (https://github.com/fmtlib/fmt) formatting header library in my c++ project.
I've added the path to the core header file at the top of my main file like so:
#include "../third_party/fmt/core.h"
but when I try to call any function like:
string message = fmt::format("The answer is {}", 42);
I get the following error:
Undefined symbols for architecture x86_64:
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > fmt::v5::internal::vformat<char>(fmt::v5::basic_string_view<char>, fmt::v5::basic_format_args<fmt::v5::buffer_context<char>::type>)", referenced from:
std::__1::basic_string<std::__1::enable_if<internal::is_string<char [17]>::value, fmt::v5::internal::char_t<char [17]>::type>::type, std::__1::char_traits<std::__1::enable_if<internal::is_string<char [17]>::value, fmt::v5::internal::char_t<char [17]>::type>::type>, std::__1::allocator<std::__1::enable_if<internal::is_string<char [17]>::value, fmt::v5::internal::char_t<char [17]>::type>::type> > fmt::v5::format<char [17], int>(char const (&) [17], int const&) in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [main] Error 1
make[1]: *** [CMakeFiles/main.dir/all] Error 2
make: *** [all] Error 2
I'm not sure how to use this as this is how I have used other header libraries in the past such as cxxopts. Any help would be appreciated!
You should link with the fmt library or use the optional header-only mode.
For example, if you have the file test.cc:
#include <fmt/core.h>
int main() {
fmt::print("The answer is {}.", 42);
}
You can compile and link it with gcc:
g++ -std=c++11 test.cc -lfmt
From a comment in #vitaut's answer, if you change your #include line from this:
#include "../third_party/fmt/core.h"
to this:
#include "../third_party/fmt/format.h"
it will cause the code to be compiled in "header-only mode", and you won't need to change your build process to compile and link in the {fmt} library.
I'm working on Mac, and I did not realize that you can install the library using brew. It appears at the end of the page. I have been dealing with symbol errors all evening, and I'm not sure that all my problems were related to the build process. The compiling process was also not working properly.
The paths where the library is installed are: /usr/local/include and /usr/local/lib.
I'm using g++-11 to build my project and this instruction works for me:
g++-11 -std=c++20 -I/usr/local/include -L/usr/local/lib -lfmt main.cpp -o main
The only problem is that it works partially. It works fine with print:
fmt::print("Don't {}!\n", "panic");
But it breaks using format:
fmt::format("Don't {}!\n", "panic");
I'm missing something, but I'm not sure what.
By the way, if you are using VSCode, you can create a c_cpp_properties.json into your .vscode folder and add the include path for the headers.
{
"includePath": [
[...],
"/usr/local/include/"
],
}
Not sure if this is related to your case, but I hope it helps.

ld: symbol(s) not found for architecture x86_64 clang: error:

This is for a Mac using Eclipse
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello, world!!!" << endl;
return 0;
}
Here is the compiler output:
Invoking: MacOS X C++ Linker g++ -o "Lab2" ./secondlab.o
Undefined symbols for architecture x86_64: "_main", referenced from: implicit entry/start for main executable ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Lab2] Error 1
All you need to do is configure the C++ Linker correctly under CDT/eclipse one has to enter "sndfile" in the text field found under:
Project->Properties->C/C++ Build->Settings->Mac OS C++
Linker->Libraries->"Libraries -l"
The "-l" gets added to "sndfile" automatically to create "-lsndfile"
It is also important however to point the Compiler to the correct include directory (containing "sndfile.h"). I guess most installations would install this into "/usr/local/include".
For a C++ project in CDT/eclipse, this would need to be entered in
Project->Properties->C/C++ Build->Settings->GCC C++
Compiler->Includes->"Include paths (-l)"
And please do take a look at this thread.

ld: symbol(s) not found for architecture

First of all I want to say I realise this has been asked a dozen times, and I've read countless solutions without any luck so therefore I'm asking again.
I'm using OS X Mavericks 10.9.5, writing in Sublime 3 and compiling using terminal with g++
I'm trying to compile this simple file (test.cpp)
#include <iostream>
#include <SDL2/SDL.h>
int main () {
if(SDL_Init(SDL_INIT_VIDEO)) {
std::cout << "I made it this far" << std::endl;
}
return 0;
}
Compiler line :
g++ test.cpp
This returns the error :
Undefined symbols for architecture x86_64:
"_SDL_Init", referenced from:
_main in test-ebbae4.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
So, I've tried adding a lot of different flags, -m32 only changes the result to throw Undefined symbols for architecture i386: and ld: symbol(s) not found for architecture i386
I've tried different -arch variations, but I can't seem to get it to work. also played around with -l -I flags but I'm not sure I know what they do/how they could help..
Does anyone have a clue what to do next?
EDIT : Some additional information. I've tried using the .framework for SDL2, that didn't change anything, currently I'm using SDL2 installed through compilation of the source. Headers located in usr/local/SDL2
g++ test.cpp
You should specify the SDL library, too:
g++ test.cpp -lsdl2
You might need to include a path if its not well known to the compiler driver:
g++ test.cpp -L/path/to/the/library -lsdl2

C++ will not run on my mac, symbol(s) not found for architecture x86_64

Heres the code, extremely basic Cpp
#include <iostream>
using namespace std;
int main(){
cout << "C++ is FUN!\n";
return 0;
}
The symbols that can not be found are "std" trying to use the name space, and "cout".
the full error message is.
make: *** [FirstProject] Error 1 FirstProject C/C++ Problem
Symbol 'cout' could not be resolved FirstProgram.cpp /FirstProject line 5 Semantic Error
Symbol 'std' could not be resolved FirstProgram.cpp /FirstProject line 2 Semantic Error
symbol(s) not found for architecture x86_64 FirstProject C/C++ Problem
EDIT:
here is the whole linker line:
make all
Building target: FirstProject
Invoking: Cross G++ Linker
g++ -o "FirstProject" ./FirstProgram.o
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [FirstProject] Error 1
Does anyone know what could potentially be the problem?
You are not compiling using a C++ compiler.
If you are using the GNU toolchain then use g++ and not gcc.
You need to compile then link:
g++ -c -o FirstProgram.o FirstProgram.c
g++ -o FirstProject FirstProgram.o
Or you can combine into one statement:
g++ -o FirstProject FirstProgram.c

Linker Error when building Xcode project using external library

I am attempting to build a very simple command line application, in Xcode, that will print out basic information about MXF video files. In order to do this I need to use the libmxf, libbmx, and libbmx libraries available for download here:
http://sourceforge.net/p/bmxlib/home/Home/
My C++ code is incredibly simple at this point:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cerrno>
#include <vector>
#include <bmx/mxf_reader/MXFFileReader.h>
#include <bmx/mxf_reader/MXFGroupReader.h>
#include <bmx/mxf_reader/MXFSequenceReader.h>
#include <bmx/mxf_reader/MXFFrameMetadata.h>
#include <bmx/MXFUtils.h>
#include <bmx/Utils.h>
using namespace std;
using namespace bmx;
#define MXF_OPEN_READ(fn, pf) mxf_disk_file_open_read(fn, pf)
int main(int argc, const char * argv[])
{
std::vector<const char *> filenames;
std::cout << "mxfheader: execution beginning...\n";
for (int cmdln_index = 0; cmdln_index < argc; cmdln_index++) {
if (!check_file_exists(argv[cmdln_index])) {
if (argv[cmdln_index][0] == '-') {
fprintf(stderr, "Unknown argument '%s'\n", argv[cmdln_index]);
} else {
fprintf(stderr, "Failed to open input filename '%s'\n", argv[cmdln_index]);
}
return 1;
}
filenames.push_back(argv[cmdln_index]);
}
std::cout << filenames[0] << "\n";
return 0;
}
When I compiled the BMX library, I was sure to run configure with 64-bit support, like so:
./configure --build=x86_64-apple-darwin11.4.2 --host=x86_64-apple-darwin11.4.2 CFLAGS="-arch x86_64" CXXFLAGS="-arch x86_64" LDFLAGS="-arch x86_64" CC=clang CXX=clang++
In the XCode Project under Build Settings, I have added /usr/local/lib to my Search Paths. Under Build Phases, I have added "libbmx-0.1.3.dylib", "libMXF-1.0.4.dylib", and "libMXF++-1.0.4.dylib" to the "Link Binary With Libraries" section.
I have verified that these libraries are, indeed, 64-bit ( file libbmx-0.1.3.dylib returns libbmx-0.1.3.dylib: Mach-O 64-bit dynamically linked shared library x86_64 ).
Every time I try and build the application, I get the following linker error:
Ld /Users/ned/Library/Developer/Xcode/DerivedData/mxfheader-bkwawmplsoqpdadfxartceqkbolo/Build/Products/Debug/mxfheader normal x86_64
cd /Users/ned/Documents/src/mxfheader
setenv MACOSX_DEPLOYMENT_TARGET 10.7
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/ned/Library/Developer/Xcode/DerivedData/mxfheader-bkwawmplsoqpdadfxartceqkbolo/Build/Products/Debug -L/usr/local/lib -F/Users/ned/Library/Developer/Xcode/DerivedData/mxfheader-bkwawmplsoqpdadfxartceqkbolo/Build/Products/Debug -filelist /Users/ned/Library/Developer/Xcode/DerivedData/mxfheader-bkwawmplsoqpdadfxartceqkbolo/Build/Intermediates/mxfheader.build/Debug/mxfheader.build/Objects-normal/x86_64/mxfheader.LinkFileList -mmacosx-version-min=10.7 -stdlib=libc++ -lbmx-0.1.3 -lMXF-1.0.4 -lMXF++-1.0.4 -o /Users/ned/Library/Developer/Xcode/DerivedData/mxfheader-bkwawmplsoqpdadfxartceqkbolo/Build/Products/Debug/mxfheader
Undefined symbols for architecture x86_64:
"bmx::check_file_exists(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any help would be appreciated. Thanks!
Your problem is the option: -stdlib=libc++ in the command line. It's causing a link to the wrong libc++, you need to make it -stdlib=libstdc++, as this is the stdlib that the libbmx library is compiled against.
under the Apple LLVM compiler options for the C++ standard library, select: libstdc++, or pick compiler default (which should choose libstdc++ also)