Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot compile C++ code on Linux, but can on Mac OS

For a project I am working on I wanted to try out the following program: http://sourceforge.net/projects/tirg/

It consists of two C++ files, but I cannot get it to compile on my laptop running Linux, while it compiles without any problem on the laptop of a friend of mine running Mac OS. I have no experience whatsoever in compiling C++ code, so it might be a beginners mistake.

The laptop running Mac OS that managed to compile the code without problems used the following g++ version:

i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)

I tried compiling the C++ files using gcc, g++, clang and clang++ on my laptop running Arch LInux (64 bit) with the following versions:

gcc and g++ (GCC) 4.8.1 20130725 (prerelease)
clang version 3.3 (tags/RELEASE_33/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix

The error I get when compiling it is:

/usr/include/c++/4.8.1/bits/stl_vector.h:1240:36: error: no matching function for call to ‘std::vector<std::vector<unsigned char> >::_M_fill_assign(int&, int&)’
         { _M_fill_assign(__n, __val); }
                                    ^

Which was caused by this line of code:

std::vector<std::vector<trg::Rgb> > a(300, 255);

I have put the complete output of the compilation on pastebin: http://pastebin.com/m285PSrH

I also had problems when compiling OpenCV, so there is probably something wrong with my configuration. I think it is a versioning problem, a wrong version of the standard library for example.

Hopefully someone with more experience in C++ can point out what might have gone wrong. Thanks!

like image 873
Matthijs Steen Avatar asked Sep 20 '13 09:09

Matthijs Steen


People also ask

Can we run C program in Linux?

GCC compiler is used to compile and run a C program on the Linux operating system. Visual Studio Code editor comes with a pre-integrated terminal, so it is easy to run and compile C programs in Linux on the Visual Studio Code editor.

Which command is used to compile C program in Linux?

The Unix command for compiling C code is gcc. This is a compiler from Gnu for Linux. If you are using a Unix machine like Solaris you may need to use the command cc.) When you compile your program the compiler produces a file containing binary code which is directly readable by the machine you are on.

Is C compiler already installed in Mac?

In our mac systems, we already have a compiler, i.e., clang installed. We will install a code editor, i.e., visual studio code, in our mac environment. Let's see how to install C on mac and work with it.


1 Answers

std::vector<std::vector<trg::Rgb> > a(300, 255);

has no sense. you wanted to write something like this:

//std::vector<std::vector<trg::Rgb> > a(picHeight, picWidth);
std::vector<std::vector<trg::Rgb> > a;
a.resize(picWidth);
{   
        std::vector<std::vector<trg::Rgb> >::iterator end = a.end();
        std::vector<std::vector<trg::Rgb> >::iterator it = a.begin();
        for(; it != end; ++it)
                it->resize(picHeight);
} 

you should correct each assign() in your code and each call to constructor of

vector<vector<XX> >
like image 170
Massimiliano Gamba Avatar answered Oct 15 '22 15:10

Massimiliano Gamba