1

I'm getting started learning c++ project building on linux with simple hello world code.

#include <iostream>

int main(){
    std::cout<<"hello,world"<<std::endl;
    return 0;
} 

When I try to run command

g++ hello.cpp

It fails with:

/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/ld: cannot find /usr/lib64/libmvec_nonshared.a
/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/ld: cannot find /lib64/libmvec.so.1

But when I try

gcc -lstdc++ hello.cpp

The compilation is successfully finished and generated executable file a.out.

So what is problem here with g++?

  • Where that compiler comes from? You compiled it yourself? Installed manually? DOes this help https://stackoverflow.com/questions/50467726/compilation-error-ld-cannot-find-libmvec-nonshared-a-libmvec-so-1-while-using? – YSC Apr 27 '21 at 12:50
  • It was installed by other person. The server I'm using have 2 version of gcc(6.3.1/4.9.2). Both of them failed with the same error. Because there are other projects running on the server I can not change the gcc version. – user5480720 Apr 27 '21 at 15:22
  • When you compile a program with C/C++ you have to specify the libraries you are using to link against. In this case you need stdc++ because you are using std::cout. The stdc++ library probably has an internal link reference to libmvc. You could do an ldd against the working executable and then do the same against each library reported. – Damian Dixon Apr 27 '21 at 15:49

0 Answers0