Error when using VScode with g++-11 compiler for C++ code on macOS Monterey v12.6 Apple M1 chip [closed] - c++

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 days ago.
Improve this question
I have installed VScode for a C++ course and the course insists on the gcc-c++ version 11 compiler. I have downloaded VScode, and used homebrew to download the compiler using the command
brew install gcc#11
and also xcode command line tools using the command
xcode-select --install.
I am slightly unsure exactly where the compiler has been installed as I was expecting it to be installed in the directory /usr/local/bin/g++-11, however, I believe that on the Apple M1 chip it is actually installed in the directory /opt/homebrew/bin/g++-11 (although I'm really not sure). I therefore set the default compiler path in VScode to be /opt/homebrew/bin/g++-11.
When I try to run build task I get an error:
ld: unsupported tapi file type '!tapi-tbd' in YAML file '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/lib/libSystem.tbd' for architecture arm64
collect2: error: ld returned 1 exit status
which I am totally baffled by and have no idea even where to start with debugging it.
I have tried a clean uninstall of VScode as well as the command line tools and compiler and then reinstalling all but I get the same error.
Has anyone else encountered similar problems?
Edit: I have solved the issue.
If you check which linker (ld) you are using with
which ld
I found that my environment was pointing towards one in a conda space as this had a higher priority in my $PATH and does not work (I'm not quite sure about why this is exactly). To solve this I made the linker in /usr/bin/ld highest priority by adding
export PATH=/usr/local/bin:$PATH
to the end of my .bash_profile hidden file in my home directory.
This file is hidden in the home directory so you should be able to view it with the command
ls -a
and then edit it using a text editor e.g I just used
vim .bash_profile
You will need to restart your bash shell for the changes to take effect.

Related

XCode ld: library not found for -lrealsense2.2.50.0 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Iam quite new to this community. Take me as a noob in software development ( Help would be appreciated )
Iam running intel based 16 inch mac. with MacOs Monterey 12.4 version and Xcode Version 13.4.1 (13F100)
Facing a problem with Xcode for C++ development, i will attach the screen shot with this. when building it shows that library not found for ld: library not found for -lrealsense2.2.50.0 clang: error: linker command failed with exit code 1 (use -v to see invocation) it was showing the same with the libfreenect2 driver as well.
Things i tried
I tried changing the name of the driver according to the name asked and added it even though it did not work.
Tried deleting the files from the derived directories and restarting everything
Creating a new project.
Building my own binary files using the SDK from link.
and lot other stuff on google, it didnt work. but when i run a cmake build with the given examples it works amazingly fine. but not when i wanted to develope my own project using the same code.
PLEASE DIRECT ME MAY BE A COURSE TOWARDS LEARNING XCODE.. anything.
This is the code iam running
And this is the error am getting

Is environment configured incorrectly inside VSCode C++ debug session on OSX?

I have a programming language I'm fiddling with and it calls clang to link the bitcode file it emits. (Perhaps there is a better way to do this all together?) I've been using Visual Studio Code to debug it and it has mostly worked great.
I recently upgraded llvm. At that point, builtin osx clang was complaining about not recognizing a bitcode construct. So I installed clang part of llvm with brew. This looks to work for the compiler but fails to call the linker.
When I run a debug session I get this in the debug window:
clang-6.0: error: unable to execute command: Executable \"ld\" doesn't exist!
However, if I run from the embedded terminal it works fine.
It seems like clang is trying to explicitly expand the location of ld rather than using builtin path resolution. Something in VSCode's C++ debugger launched environment is causing issues with it.
Some supporting bits of diagnosis (trying to keep this a bit short for now...).
When run from the debugger:
whereis ld works and emits...
/usr/bin/ld
env emits what looks like a wrapped environment...
PWD=/Users/<snipped>
SHLVL=1
_=/usr/bin/env
echo $PATH emits...
/usr/gnu/bin:/usr/local/bin:/bin:/usr/bin:.
And clang tries to link it runs "ld" and says...
clang-6.0: error: unable to execute command: Executable "ld" doesn't exist!
When run from the embedded terminal on the other hand:
whereis ld works and emits...
/usr/bin/ld
env emits...
a metric ton of stuff including
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
echo $PATH emits...
/usr/gnu/bin:/usr/local/bin:/bin:/usr/bin:.
And clang tries to run "/usr/bin/ld" which works fine.
I realize this may be a clang ld lookup bug (not correctly expanding _=/usr/bin/env??). Unfortunately A) I don't know very much about OSX environment expansion B) if VSCode C++ debugger is using some sort of standard OSX environment jujitsu or not C) not sure how to debug clang run from within an existing VSCode debugger session D) don't know how to emulate the VSCode debugger environment setup to get started unravelling the ball of yarn.
I think I've upgraded OSX/XCode that I'm now unblocked (using the builtin clang compiler from within the VSCode debugger works again). I figured I'd raise this anyway in case I can get a problem fixed or at least learn something.
Any thoughts/suggestions?
Thanks,
Adrian

'wchar.h' file not found

I know about this question: macOS 'wchar.h' File Not Found
but it did not help me. I've tried reinstalling xcode, reinstalling command line tools, restarting the system. wchar.h file is in place, but the compiler does not manage to find it. What else could I try? Maybe it is sysroot related? Any way to fix that?
macbooks-MacBook-Pro:Rack euphorbium$ sudo make
c++ -Iinclude -Idep/include -Idep/lib/libzip/include -DVERSION=dev -MMD -O3 -march=core2 -ffast-math -g -Wall -DARCH_MAC -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk -mmacosx-version-min=10.7 -DAPPLE -stdlib=libc++ -std=c++11 -stdlib=libc++ -c -o build/src/app.cpp.o src/app.cpp
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk' [-Wmissing-sysroot]
In file included from src/app.cpp:1:
In file included from include/app.hpp:2:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/vector:265:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/iosfwd:90:
/Library/Developer/CommandLineTools/usr/include/c++/v1/wchar.h:119:15: fatal error:
'wchar.h' file not found
#include_next <wchar.h>
^~~~~~~~~
1 error generated.
make: *** [build/src/app.cpp.o] Error 1
since wchar.h exists both in the xcode app, and in the /Library/Developer/CommandLineTools I think that it looks for it in some completely unrelated folder.
I had the same problem after upgrading to macOS High Sierra. A project which was compiling before stopped working with this error. In my case, the project files had been generated by the CMake application. The solution was to run CMake, 'Delete Cache', and 'Configure' the project again. This corrected the sysroot directory reference in the make files to point to the new SDK and the error was resolved.
I've got the same problem. I was able to fix it by using a symbolic link.
This is what I made :
cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
sudo ln -s MacOSX.sdk MacOSX10.07.sdk
Then enter your root password.
NB: you have to adapt the last line with required sdk.
For any one struggling with this on MacOSX Mojave this answer solves it. In short:
Go to the terminal and run open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg This will bring up the prompt to install Xcode tools.
After that's done got to the terminal and run sudo xcode-select -s /Library/Developer/CommandLineTools
My system is macOS Mojave, and I've fixed this problem by running this command line:
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
It was caused by incorrect sysroot, (set for an older mac os version) set in makefiles.
If you are using CLion, follow these steps :
Click on CMake at the bottom center of your IDE
Click on the Settings Gear Icon at the left
Click on Reset Cache and Reload Project
Took me 3 hours to find this solution.
FYI this project was running fine on Bug Sur 11.3 but failed to build after I upgraded to Big Sur 11.4
Set an environment variable
SDKROOT="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk"
and reopen Terminal. This solves the header not found issue.
To see where the compiler finds headers, run with -v
clang -v test.c
For my case, this problem result from that MacOS changes the headers's path.
Check this note: MacOS release note.
So the solution is to make the compiler can find those headers.
My macOS version is Catalina 10.15, and XCode Version 12.4. For this version, it seems that /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg is not provided anymore and thus the sulotions above do not work for me.
This method saved my night: Fixing C++ compilation bugs for the MacOS Catalina upgrade. Note that if you follow its steps and errors that some global symbols are not found arise, do not modify the LIBRARY_PATH as it says.
I did something dumb but it did fix the problem... Not sure if it will work for your computer though.
Here is what I did:
I originally installed c++ using Homebrew on my MacBook on Mojave... so I had to manually install the Xcode CommandLineTools using the installer found at /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg . Then I copied the "c++" folder contents from to folder /Library/Developer/CommandLineTools/usr/include/c++/v1 to the folder where I want the missing file to be, at /usr/local/Cellar/gcc/8.2.0/include/c++/8.2.0 , while replacing files with the same names.
The trick worked, since now the missing file "wchar.h" is right where it should be... Your settings is probably not the same, however, I am afraid.

Header Files not Working in CLion after Xcode update

Apple sent out an Xcode update today and little did I know it would mess with my all of my header files.
The header file I am attempting to use is time.h. I know the code if fully functional because an online C++ shell will run it fine but CLion is telling me Cannot find 'time.h'. When I attempt to run the program I receive the following:fatal error: 'wchar.h' file not found. This was odd because I was able to locate the wchar.h file.
As per this post, I have followed all the instructions to no avail. I have also checked the location of the Command Line Tools with xcode-select -p and received that they are in /Library/Developer/CommandLineTools, which seems to be correct. I have also checked that gcc is working and the correct version. Any time I try xcode-select --install at this point it just tells me that it is installed and check for updates if I think it is wrong. It also told me there were no updates.
The only other thing I can think of is that the compiler is also telling me the following:
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk' [-Wmissing-sysroot]
And after checking this directory, I noticed that my sdk is MacOSX 10.13 where the compiler was looking for 10.12. Also my SDK is just a 10 byte alias file that OS X tells me can't be found when I click on it?
I am really scratching my head on this one, I have re-installed Xcode already just as a last resort to no avail. Any help would be much appreciated.
You need to change the sdk your project is using. Go to your Target and look at the Build Settings. Set the Base SDK popup to "Latest Mac OS(...)" and you should be good to go.

Undefined function for input arguments of type 'double' [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I downloaded the MATLAB code from here http://cazencott.info/dotclear/public/code/scones.zip. When I run 'demo', it says "Undefined function 'maxflowmex' for input arguments of type 'double'". In fact there is only a c++ file "maxflowmex.cpp" in the folder (already added to path). Whether it needs a "maxflowmex.m" instead of "maxflowmex.cpp" to run properly? Or some other methods to call "maxflowmex.cpp"? Or I need to compile something?
I just took a look at the zip file. There are MEX wrappers in the maxflow directory that are written where MATLAB calls these functions which are written in C, but are runnable in MATLAB. These MEX wrappers need to be compiled using a compiler that is compatible for your operating system before you run them.
However, there are pre-compiled binaries, but I only see 64-bit binaries for Linux and Mac OS and I don't see Windows binaries. Because you can't run them, you are most likely running a 32-bit operating system or Windows. I suspect you are running either Windows or 32-bit Linux, as Mac OS by default ships out as 64-bit.
There is a make.m script that you need to run so that you can compile the maxflow library for your machine. Once you compile the library, running demo.m should be successful.
Before you do that, you need to make sure you set up mex by doing mex -setup in the command window, then choose the right compiler. Once you do this, run make.m that's inside the maxflow directory.
If you don't have a compiler, if you're using Linux, doing an apt-get on the gcc packages should be good enough, so:
sudo apt-get update
sudo apt-get install gcc-4.6-base g++-4.6 cpp-4.6 libgomp1 libquadmath0 libc6-dev
If you are using Windows, then the supported compiler that you need will depend on what version of MATLAB you are using. I'm assuming you are using the latest one, and so downloading the latest version of Visual Studio Express as well as the SDK should be sufficient.
http://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx
http://www.microsoft.com/en-us/download/details.aspx?id=40758