how to use llvm::cl::ParseCommandLineOptions> - Linking error - llvm

I am trying to use llvm::cl to parse command line arguments. As the start, I am trying to write a simple driver that parses an input file from the command line via llvm::cl::ParseCommandLineOptions.
#include "llvm/Support/CommandLine.h"
int main(int argc, char *argv[]) {
llvm::cl::ParseCommandLineOptions(argc, argv, "quad2bitcode generator\n");
llvm::cl::opt<std::string> InputFilename(llvm::cl::Positional,
llvm::cl::desc("<input file>"),
llvm::cl::Required);
...
When compiling, I am getting the following linking error. Any help will be appreciated!
Undefined symbols for architecture x86_64:
"__ZTIN4llvm2cl18GenericOptionValueE", referenced from:
__ZTIN4llvm2cl15OptionValueCopyINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE in quadreader.cpp.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

Related

unable to run c++ in visual studio code on m1 chipset

I have wrote a very simple program in c++
#include<iostream>
using namespace std;
int main()
{
cout<<"hello world";
return 0;
}
but its showing error in
Undefined symbols for architecture arm64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
please help me with this

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 ?

Error when compiling with mpifort

I have downloaded OpenMPI, but after trying to run a simple parallelized Hello world program I get the following error:
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
I guess there is a problem with the compiler because I struggled quite a lot to install OpenMPI.
In order to get that error I typed from the terminal:
mpifort -o hello.f90
Someone can help me?

C++ Compiling with Python.h Undefined Symbols

So, I've been trying to start using Python.h for a little project I want to work on that seems pretty /simple/. But before I start I want to try to learn how to use Python.h.
So I found this little example online.
#include "Python/Python.h"
int main(int argc, char** argv)
{
Py_Initialize();
PyRun_SimpleString("print 'Test'");
PyRun_SimpleString("print str(3 + 5)");
Py_Exit(0);
}
Seems pretty straight forward. When i first used
gcc test.cpp
to compile, i got some undefined symbols. I quickly found out I should use
-lpython2.7
then I found out I could also use
-L/Library/Frameworks/Python.framework/Versions/2.7/lib/
that didn't work (I made sure that /Library/Frameworks/Python/Versions/2.7/lib/ existed)
I'm stuck, what do I do?
I get
Undefined symbols:
"_Py_Initialize", referenced from:
_main in ccoUOSlc.o
"_PyRun_SimpleStringFlags", referenced from:
_main in ccoUOSlc.o
_main in ccoUOSlc.o
"___gxx_personality_v0", referenced from:
_main in ccoUOSlc.o
CIE in ccoUOSlc.o
"_Py_Exit", referenced from:
_main in ccoUOSlc.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
EDIT:
I just tried using the -Framework argument, and tried adding after the -L the -l python2.7 argument, and I now get
Undefined symbols:
"___gxx_personality_v0", referenced from:
_main in ccfvtJ4j.o
CIE in ccfvtJ4j.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Now what?
If you are using an Python framework installation on OS X as it appears you are based on the paths, you can use the -framework argument to the Apple compiler drivers:
cc test.cpp -framework Python
Alternatively, you can explicitly specify the directory path and library name:
cc test.cpp -L /Library/Frameworks/Python.framework/Versions/2.7/lib/ -l python2.7
Update: With the configuration you report in the comments (Xcode 3.2.6, gcc-4.2), it appears you need to explicitly invoke the c++ variant of gcc. Either:
g++ test.cpp -framework Python
or
c++ test.cpp -framework Python
should work.