Cannot compile C++ files after CommandLineTools installed - c++

Backstory: I started using my terminal for a lot of my school projects. I recently got familiar with it and wanted to "upgrade" by installing iTerm2 and homebrew; but before I installed the two, I was able to compile my C++ homework files "g++ filename.cpp" and run "./a.out" no problem. After installing iTerm2 and homebrew followed by xcode commandline tools I started running into this problem every time I try to compile my c++ files:
"ld: unsupported tapi file type '!tapi-tbd' in YAML file '/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/lib/libSystem.tbd' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)"
I created a simple "Hello World!" c++ and that won't even compile. I've tried everything even some posts on here. Hopefully someone has a different solution. Thank you in advance!
The code is super simple:
#include<iostream>
using namespace std;
int main() {
cout << "Hello World!" << endl;
return 0;
}
How I tried compiling it: "g++ main.cpp"
Which back then I get an a.out file but this time I get that error message shown in the picture.
I added more photos showing my g++ version and also the attempt of compiling it: "g++ -Wall -Wextra -g main.cpp -o prog.bin"
I'm also running macOS Catalina 10.15.6
Thank you in advance. I'm reading through the documentations provided rn.
g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
enter image description here
UPDATE:
I uninstalled and reinstalled Xcode CommandLineTools and homebrew; however, this time I did not update the CommandLineTools to beta 5 like I did before.
Now I'm able to compile and run my school assignments. Not an ideal solution but I'm back to working on my school assignments peacefully. Thank you all for the help!! I guess installing the beta CommandLineTools is not such a great idea.

Related

Gcc not working on MacOS 10.15.4 Catalina?

I wanted to start writing c++ code again and I just realized that the homebrew version of gcc does not compile any c++, c, or even fortran programs.
For example, I tried to compile the following simple hello_world.cpp program:
#include<iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
using
g++-9 hello_world.cpp
The output I get is:
FATAL:/usr/local/Cellar/cctools/855/bin/../libexec/as/x86_64/as: I don't understand 'm' flag!
I tried installing gcc#8, gcc#7, and compile but I still get the same message.
Moreover, the same error message is shown when I try to compile a hello_world.c program using gcc-9 and a hello_world.f90 program using gfortran-9.
The programs *.c and *.cpp compile fine with the clang and clang++ compilers respectively. I also learned that as is an assembler, and that gcc can output a *.s file using the flag gcc -S but I still don't understand the error message.
I think I exhausted my c++ knowledge and internet search before posting so thank you in advance!
I ended up reinstalling all packages using
brew list | xargs brew reinstall
This fixed the problem!
For anyone else who has stumbled across this problem, you do not need to reinstall all of your brew packages. The troublemaker is cctools, which is no longer in the brew formulae list. If for some reason it is still hanging around on your system, you can either
mv /usr/local/Cellar/cctools{,-backup}
to make sure it is no longer seen by the gcc tool suite installed through homebrew, or you can outright remove it
brew uninstall cctools
I opted for the first, at the moment, because I am not sure what, if anything, removal would break. Once I have confirmed that there are no ill effects caused by not having this installed, I will remove it altogether from my system. That being said, I have confirmed that simply moving the directory takes care of the
FATAL:/usr/local/Cellar/cctools/855/bin/../libexec/as/x86_64/as: I don't understand 'm' flag!
error being reported when you try and compile something with the GNU compiler on Mac OSX (in my case Catalina, but should be the same for Big Sur and Monterrey).

Automatic instrumentation with Score-P / Vampirtrace not working with gcc/g++

I have a simple helloworld.cpp to instrument with Score-P or Vampirtrace.
Installation of the performance/ tracing tools works fine. After compiling and running:
# score-p
scorep-g++ helloworld.cpp -o hello
export SCOREP_ENABLE_TRACING=true
export SCOREP_ENABLE_PROFILING=true
# vampirtrace
vtcxx -DVTRACE helloworld.cpp -o hello
# run
./hello
The created OTF files (OTF for vampirtrace/ OTF2 for Score-P) are more or less empty (no timeline data). I'm using Vampir to visualize the data.
More details:
I'm testing on Mac OS X (g++-8) and Xubuntu (g++-7; VirtualBox).
For Mac OS X I have installed brew install gcc.
For the instrumented Score-P version I also got a warning
[Score-P] src/measurement/profiling/scorep_profile_callpath.c:206: Warning: Master thread contains no regions.
but I can't find related issues/ help.
I also installed TAU and PDT for Vampirtrace, but nothing changed. By the way manual instrumentation works for Vampirtrace:
#include "vt_user.h"
...
VT_TRACER("name");
For Vampirtrace I also tested OpenMP instrumentation and this was working, but only that (no application tracing around).
For both environments I did not install Open MPI.
It would be great, if somebody has similar issues and could help.
PS: Later, I want to instrument an application with Poco::Threads. I only read about partial support for POSIX Threads.
Update
The problem is g++. I tried the same instrumentation with Intel icc and it worked.
The missing instrumentation with g++ is also possible with icc, if you add the parameter --nocompiler like
score-p --nocompiler icc helloworld.cpp -o hello
Update
I had to install missing packages. There are logging outputs for ./configure with hints. One of the following package solved it:
apt-get install llvm libwrap0-dev libclang-dev gcc-7-plugin-dev

how to compile c++ program in mac terminal

i wrote a program in my mac using sublime text as the plateform..
#include<iostream>
using namespace std;
int main()
{
cout<<"HELLOW WORLD";
return 0;
}
this was my program..
i saved it in desktop as hellow.cpp
while compiling on mac terminal as g++ hellow.cpp, i found an error
adarshs-MacBook-Air:Desktop adarshak$ g++ hellow.cpp
xcrun: error: invalid active developer path
(/Library/Developer/CommandLineTools), missing xcrun at:
/Library/Developer/CommandLineTools/usr/bin/xcrun
anyone plese help me to find out the error
It sounds like you don't have the command line developer tools installed. Run this command from Terminal once:
xcode-select --install
This will bring up the download & installation UI. Follow this through to the end. (It may take a while depending on the speed of your internet connection.)
From then on compiling should work.

Compiling phantom.js to LLVM IR

I downloaded the phantomjs source off of their github. I am trying to compile phantomjs into LLVM bytecode. However, when I run
> clang -S -emit-llvm main.cpp
It keeps saying:
In file included from main.cpp:31:
./utils.h:34:10: fatal error: 'QtGlobal' file not found
#include <QtGlobal>
^
1 error generated.
I'm on Ubuntu 14.04. Do I need to install Qt or something?
BTW, I'm not sure if StackOverflow is the best place to ask this, but I couldn't think of any other SE site that would be better.

gmon.out isn't created when I compile with -pg flag with g++

I'm running on Mac OSX, version 10.8.5 (Mountain Lion). I have the following simple C++ code.
main.cpp:
#include <iostream>
int main ()
{
std::cout << "Hello world!"<<std::endl;
std::cout << "Goodbye world!"<<std::endl;
return 0;
}
I'm trying to get gprof to work on my computer. As the manual suggests, I enter the following two lines into my terminal:
g++ -g -pg main.cpp -o a.out
./a.out
However this does not generate a gmon.out file as it is supposed to. When I try typing gprof in the terminal, it says:
gprof: can't open: gmon.out (No such file or directory)
which is to be expected since gmon.out isn't there...
Any ideas on what I'm doing wrong?
EDIT: Some other things that may help:
My friend, who has a similar OS X version (I can ask him later to confirm), and the exact same versions of g++ and gprof, was able to
use gprof successfully as I have outlined.
I'm using an older version of g++ but I have read online that updating to a newer version didn't help.
a.out works perfectly, it prints out Hello world! and Goodbye world!. I also tried this with a more complex C++ program with
several classes and it still has the same problem. Everything
compiles and runs normally but no gmon.out file is produced.
You have to realize that OS X/MacOS does not provide GNU GCC on the system by default.
Note the output of this command:
ls -la /usr/bin/g++ /usr/bin/clang++
These executables look identical. (Actually! It looks like they are different, but somehow the filesize is identical!)
As far as I can tell, clang doesn't support the production of gprof output. As confusing as it may be, the gcc program will run clang.
I would recommend trying to use homebrew to install GCC on OS X/MacOS. You do want to be careful about how it gets installed, etc., so that you know which command corresponds to which compiler.