Linking C++ code to a DYLIB library in macOS - c++

I was able to setup BlockSci on macOS v10.13 (High Sierra) 10.13.6. The setup installed header files in /usr/local/include and a libblocksci.dylib in /usr/local/lib. The C++ code I am trying to compile is:
#include "blocksci.hpp"
#include <iostream>
#include <string>
int main(int argc, const char * argv[]) {
blocksci::Blockchain chain{"path/config.json"};
return 0;
};
The compile command I am using for hello.cpp is:
g++ -std=c++17 -L/usr/local/lib -I/usr/local/include/blocksci -I/usr/local/include/blocksci/external -o hello hello.cpp
However, the symbols for the BlockSci library are not found:
Undefined symbols for architecture x86_64:
"blocksci::Blockchain::Blockchain(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
_main in hello-942a60.o
"blocksci::Blockchain::~Blockchain()", referenced from:
_main in hello-942a60.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What am I doing wrong when I try to compile this?

I found this and this that were helpful. It finally compiled with:
g++ hello.cpp -std=c++17 -I/usr/local/include/blocksci/external -o hello -L/usr/local/lib -lblocksci -Wl,-rpath,/usr/local/lib
However, now I get a runtime error:
libc++abi.dylib: terminating with uncaught exception of type std::runtime_error
Abort trap: 6
Back to the drawing board, but it compiled for now.

Related

How to use fmt library in the header-only mode?

Having a hard time using the header-only mode of fmt library. Here is what I tried in details:
I downloaded fmt7.1.3 from https://fmt.dev/latest/index.html, only put the directory fmt-7.1.3/include/fmt in a directory ([trgdir]) and wrote a test.cpp as follow:
#include <iostream>
#include <fmt/format.h>
int main() {
fmt::format("The answer is {}.", 42);
return 0;
}
Then in the terminal I use
gcc -I[trgdir] test.cpp
where gcc I defined as
alias gcc='gcc-10 -xc++ -lstdc++ -shared-libgcc -std=c++17 -O2 '
I got the error goes as
Undefined symbols for architecture x86_64:
"__ZN3fmt2v76detail7vformatB5cxx11ENS0_17basic_string_viewIcEENS0_11format_argsE", referenced from:
_main in ccEeTo0w.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
I have checked this post but I still cannot solve my issue. How to use the fmt library without getting "Undefined symbols for architecture x86_64"
You need to define a macro before include, like this:
#define FMT_HEADER_ONLY
#include "fmt/format.h"

Firebase : Undefined symbols for architecture x86_64 (Configure Multiple project)

I am trying to compile main.ccp to configure my c++ project manually and have it connect to my own firebase.
#include "main.hpp"
#include <iostream>
#include "firebase/app.h"
#include "firebase/database.h"
int main()
{
firebase::AppOptions secondary_app_options;
secondary_app_options.set_api_key("API_KEY");
secondary_app_options.set_app_id("APP_ID");
secondary_app_options.set_project_id("PROJ_ID");
firebase::App* secondary_app = firebase::App::Create(secondary_app_options, "Secondary");
firebase::database::Database* secondary_database = firebase::database::Database::GetInstance(secondary_app);
return 0;
}
I use the command line to compile : g++ -std=c++11 main.cpp -o main.o
And it output:
Undefined symbols for architecture x86_64:
"firebase::App::Create(firebase::AppOptions const&, char const*)", referenced from:
_main in main-9988c0.o
"firebase::database::Database::GetInstance(firebase::App*, firebase::InitResult*)", referenced from:
_main in main-9988c0.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I did correctly download and locate all of the framework and library for firebase already. Can anybody help me with this ?

Compilation Error Undefined symbols for architecture x86_64:

I have a program that i am trying to compile from my project directory and haven't been able to wrap my head around the following error
My compilation command
g++ grades.cpp -o grades
I see the following error
Undefined symbols for architecture x86_64:
"tbb::task_scheduler_init::initialize(int, unsigned long)", referenced from:
tbb::task_scheduler_init::task_scheduler_init(int, unsigned long) in grades-9c8d1a.o
"tbb::task_scheduler_init::terminate()", referenced from:
tbb::task_scheduler_init::~task_scheduler_init() in grades-9c8d1a.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am not sure how to debug this error.
You need to link against the tbb library you are tying to use,
g++ grades.cpp -o grades -ltbb

G++ / clang Linker issues, OSX

g++ -std=c++11 -lstdc++ -o ./bin/game -framework SFML -lsfml-graphics -lsfml-audio -lsfml-window -lsfml-system -Iinclude main.cpp
Undefined symbols for architecture x86_64:
"Game::run()", referenced from:
_main in main-1dfef1.o
"Game::Game()", referenced from:
_main in main-1dfef1.o
"Game::~Game()", referenced from:
_main in main-1dfef1.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: *** [main] Error 1
I've seen that this is a common error, but I can't for the life of me figure out what's going wrong here. I installed SFML in the frameworks Library/Frameworks folder on OSX (Yosemite) as instructed on the SFML site. You can see my build command in the snippet above (I've actually tried a number of different variations of this). If I don't include the SFML stuff, I still get the error. With -v the output is: http://pastebin.com/WAGC76a2
I can't glean from that what may be causing this, though. Any ideas?

Lear Gist Descriptor C code used with C++

I am using Lear's implementation of the Gist descriptor for a project which can be found here: http://lear.inrialpes.fr/software.
I am writing an application in c++ and I want to use this library. I am having issues though with the makefile and linking in general.
These commands give me no errors:
g++ -c standalone_image.c -o standalone_image.o
g++ -c gist.c -o gist.o
However, this line
g++ compute_gist.c `pkg-config --cflags --libs opencv`
gives me the following error
Undefined symbols for architecture x86_64:
"color_gist_scaletab(color_image_t*, int, int, int const*)", referenced from:
_main in ccMFYbAU.o
"color_image_delete(color_image_t*)", referenced from:
_main in ccMFYbAU.o
"color_image_new(int, int)", referenced from:
load_ppm(char const*)in ccMFYbAU.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
I have the Mosaic c++ code in a different directory. I also tried to compile gist and standalone_image seperately, copy into the mosaic directory, and compile the Mosaic code.
Which gives me the following error:
Undefined symbols for architecture x86_64:
"color_gist_scaletab(color_image_t*, int, int, int const*)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [mosaic] Error 1
I really want to use this library in my project, but I can't figure out a way to incorporate it in my c++.
Any help is GREATLY appreciated! Thanks!
Edit: I am using Mac Lion with:
gcc + g++ version: i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)
The lear library also uses the FFTW3 library that should work with C and C++.
The problem was that I needed the extern around the gist include, but the linking that was done in the Makefile was also wrong. It works now. :)