Errors while compiling C++ file including LLVM API headers - c++

Hello,
I have installed llvm and llvm-debuginfo using apt install and am trying to compile this file:
llvm_test.cpp
#include <stdio.h>
#include "llvm/IR/LLVMContext.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/IR/Module.h"
int main( int argc, char* argv[] )
{
if( argc < 2 )
llvm::errs() << "Expected an argument - IR file name\n";
llvm::LLVMContext &context = llvm::getGlobalContext();
llvm::SMDiagnostic err;
llvm::Module* module = llvm::ParseIRFile( argv[1], err, context );
if( !mod )
{
err.print( argv[0], errs() );
return 1;
}
return 0;
}
Using following command:
$ clang++ -std=c++11 llvm_test.cpp `llvm-config --system-libs --cppflags --ldflags --libs core` -o llvm_test
But it doesn't seem to find required API headers. This is the error message:
llvm_test.cpp:9:13: error: no member named 'errs' in namespace 'llvm'
llvm::errs() << "Expected an argument - IR file name\n";
~~~~~~^
llvm_test.cpp:11:39: error: no member named 'getGlobalContext' in namespace
'llvm'
llvm::LLVMContext &context = llvm::getGlobalContext();
~~~~~~^
llvm_test.cpp:13:33: error: no member named 'ParseIRFile' in namespace 'llvm'
llvm::Module* module = llvm::ParseIRFile( argv[1], err, context );
~~~~~~^
llvm_test.cpp:15:9: error: use of undeclared identifier 'mod'
if( !mod )
^
llvm_test.cpp:17:27: error: use of undeclared identifier 'errs'
err.print( argv[0], errs() );
^
5 errors generated.
Adding "support" to llvm-config arguments, as suggested in comments, doesn't change anything: same errors.
What is wrong with this?
Note: I am using Cygwin on Windows and I meant apt-cyg (apt like tool for Cygwin) under apt.

1) error: no member named 'errs' in namespace 'llvm'
You must include: #include "llvm/Support/raw_ostream.h"
2) error: no member named 'getGlobalContext' in namespace
It is due to getGlobalContext was removed after llvm 3.6. So use: LLVMContext context; and give a reference of it where required.
3) error: no member named 'ParseIRFile' in namespace 'llvm'
You must include: #include "llvm/IRReader/IRReader.h"
4)error: use of undeclared identifier 'mod'
Use module instead of mod in here

If you need errs, you should include the right header:
#include "llvm/Support/raw_ostream.h"
ParseIRFile should be in llvm/IRReader/IRReader.h
#include "llvm/IRReader/IRReader.h"

Related

Possible namespace errors in OpenCV header files

I'm just now getting into OpenCV (4.1.0) in C++ (relatively new to both) and I'm getting an odd error from simply including some header files. (GCC 6.3.0)
Error:
from c:\Users\Logan\Projects\Code\C++\webcamTest.cpp:1:
C:\Users\Logan\Projects\Code\C++\Includes\opencv\build\include/opencv2/core/utility.hpp:697:14: error: 'recursive_mutex' in namespace 'std' does not name a type
typedef std::recursive_mutex Mutex;
^~~~~~~~~~~~~~~
C:\Users\Logan\Projects\Code\C++\Includes\opencv\build\include/opencv2/core/utility.hpp:698:25: error: 'Mutex' is not a member of 'cv'
typedef std::lock_guard<cv::Mutex> AutoLock;
^~
C:\Users\Logan\Projects\Code\C++\Includes\opencv\build\include/opencv2/core/utility.hpp:698:25: error: 'Mutex' is not a member of 'cv'
C:\Users\Logan\Projects\Code\C++\Includes\opencv\build\include/opencv2/core/utility.hpp:698:34: error: template argument 1 is invalid
typedef std::lock_guard<cv::Mutex> AutoLock;
Code:
#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
int main()
{
return 0;
}
To me this looks like an error with the way the headers are set up, but perhaps I didn't set something up correctly?
Currently the command I'm using is as follows:
g++ -std=c++11 -g -I C:\\Users\\Logan\\Projects\\Code\\C++\\Includes\\opencv\\build\\include -o C:\\Users\\Logan\\Projects\\Code\\C++\\Bins\\<File name I'm using in the editor>.exe <File I'm using in the editor>

error: 'to_string' was not declared in this scope in Windows using cmd

I'm trying compile this code in cmd:
#include <iostream>
#include <string>
using namespace std;
int main(){
int n = 24;
string s = to_string(n);
cout<<s;
}
I found in another qestions, that I should use this command:
g++ -std=c++11 main.cpp
but I get error:
main.cpp: In function 'int main()':
main.cpp:7:24: error: 'to_string' was not declared in this scope
string s = to_string(n);
^
I have latest g++ compiler for Windows v. 5.3.0. I used this installer for MinGW.
I tried solve in to_string is not a member of std, says g++, but this patch doesn't work.
How can I compile this code in command line in Windows?

compilation errors when trying to include boost/any.hpp from boost

I am not sure what happened to my system, but now when I try to include boost/any.hpp in a program test.cc
#include <iostream>
#include <boost/any.hpp>
int main(int argc, char *argv[])
{
std::cout << "hello" << std::endl;
return 0;
}
using g++ -o test test.cc, I get the following error:
In file included from test.cc:2:0:
/usr/include/boost/any.hpp: In function 'ValueType boost::any_cast(boost::any&)':
/usr/include/boost/any.hpp:278:52: error: 'if_' in namespace 'boost::mpl' does not name a template type
typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_<
^ /usr/include/boost/any.hpp:278:55: error: expected unqualified-id before '<' token
typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_<
^ /usr/include/boost/any.hpp:284:28: error: 'ref_type' does not name a type
return static_cast<ref_type>(*result);
Everything is fine when I remove the include to any.hpp. I am using boost-1.56.0 and gcc-4.9.3.
Things were compiling fine a week ago, but I am not sure what I might have updated to cause this error. Any help would be appreciated.

Algorithm header llrint, llround compiler error

I'm learning C++ and I'm at the point of using the <algorithm> header and I get this compiler error even with an empty project:
/Users/italrolando/hpc-gcc47/bin/../lib/gcc/x86_64-apple-darwin11.4.0/4.7.1/../../../../include/c++/4.7.1/cmath:1108:11: error: '::llrint' has not been declared
/Users/italrolando/hpc-gcc47/bin/../lib/gcc/x86_64-apple-darwin11.4.0/4.7.1/../../../../include/c++/4.7.1/cmath:1109:11: error: '::llrintf' has not been declared
/Users/italrolando/hpc-gcc47/bin/../lib/gcc/x86_64-apple-darwin11.4.0/4.7.1/../../../../include/c++/4.7.1/cmath:1110:11: error: '::llrintl' has not been declared
/Users/italrolando/hpc-gcc47/bin/../lib/gcc/x86_64-apple-darwin11.4.0/4.7.1/../../../../include/c++/4.7.1/cmath:1112:11: error: '::llround' has not been declared
/Users/italrolando/hpc-gcc47/bin/../lib/gcc/x86_64-apple-darwin11.4.0/4.7.1/../../../../include/c++/4.7.1/cmath:1113:11: error: '::llroundf' has not been declared
/Users/italrolando/hpc-gcc47/bin/../lib/gcc/x86_64-apple-darwin11.4.0/4.7.1/../../../../include/c++/4.7.1/cmath:1114:11: error: '::llroundl' has not been declared
make: *** [algorithm.o] Error 1
Here is the code:
#include <iostream>
#include <algorithm>
using namespace std;
int main( int argc, char ** argv ){
return 0;
}
I'm using Eclipse with GCC 4.7.1 compiler and it's quite strange since the course I'm following is using Eclipse with Gcc 4.7 and it works.
Thanks

FI_Init_FreeType variable declaration error

I am trying to write a simple program that uses freetype.
code :
#include <ft2build.h>
#include FT_FREETYPE_H
int main()
{
FT_Library library;
int error = FI_Init_FreeType(&library);
}
i am compiling as g++ try1_c++demo.cpp -I/usr/include/freetype2
it gives following error:
try1_c++demo.cpp: In function ‘int main()’:
try1_c++demo.cpp:9: error: ‘FI_Init_FreeType’ was not declared in this scope
how do i solve this error?