I am tying to launch a debugging of clang code via lldb. I'm using a WSL Ubuntu 20.04 LTS. I installed a clang and lldb via sudo apt-get install clang and sudo apt-get install lldb accordingly.
The test code (mytest.cpp) is the following:
#include <iostream>
int main()
{
std::cout << "TEST" << std::endl;
return 0;
}
Compilation command: clang++ -g -std=c++17 -o mytest mytest.cpp
Then I calling a debugger:
lldb mytest
(lldb) target create "mytest"
Current executable set to '/home/adzol/Projects/mytest' (x86_64).
(lldb) r
Process 51 launched: '/home/adzol/Projects/mytest' (x86_64)
And that's it. Nothing is happening. What can be wrong here?
But if I am calling my executable file directly, I am getting expected console output:
./mytest
TEST
I found out that the problem was is WSL 1. I updated my WSL to WSL 2 and this all works.
Related
*Update:
Regarding the similar question macos-wchar-h-file-not-found, the command line tool switch(xcode-select --install) doesn't exist anymore.
I am running on macOS Monterey system and I am trying to compile a simple hello world .cpp file using the g++-11 commend (I installed gcc using homebrew), I am getting the following error:
/usr/local/Cellar/gcc/11.2.0_3/include/c++/11/cwchar:44:10: fatal error: wchar.h: No such file or directory
44 | #include <wchar.h>
| ^~~~~~~~~
I tried two compile commands:
g++-11 -c hello.cpp -o hell.o
g++-11 -std=c++11 -c hello.cpp -o hell.o
Here is the file I am trying to compile:
//
// main.cpp
// Test
//
// Created by Jiali Zhu on 1/9/22.
//
#include <iostream>
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}
I also had the same problem and in my case the problem was outdated
command line developer tools.
I found out it by running
$ brew doctor
...
Warning: Your Command Line Tools are too outdated.
Update them from Software Update in System Preferences or run:
softwareupdate --all --install --force
If that doesn't show you any updates, run:
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
Alternatively, manually download them from:
https://developer.apple.com/download/all/.
You should download the Command Line Tools for Xcode 13.1.
I tried to update them via softwareupdate -l, however this did not give me any update information.
So removed them and reinstalled with xcode-select --install.
After this g++-11 stopped giving me an error about this header.
Now brew config tells me that I have CLT: 13.0.0.0.1.1627064638
P.S.
Also I started the xcode and it asked me whether additional components need to be installed and I said yes.
I installed geany and wsl (Ubuntu) for competitive programming. I've noticed that unlike Linux there is no terminal for geany in windows. I like to know if there is a way to get terminal in geany for windows version and also is there a way to set build commands in geany to compile c++ files with wsl.
Install gcc in your wsl(Ubuntu)
sudo apt install g++
Config Geany
Build: wsl gcc -Wall -o "%e" "%f"
Execute: wsl "./%e"
I have been trying to compile a simple hello world program in c++ using clang. Now in the past I have been able to do this using the command:
clang -lc++ hello.cpp -o hello
When I try this I get the error:
/usr/bin/ld: cannot find -lc++
Clang: error : linker command failed with exit code 1
If I use g++ it compiles without errors. Why is this problem occurring with clang?
You need to install libc++ library.
Try if are using ubuntu:
sudo bash -c "cat >> /etc/apt/sources.list" << LLVMAPT
# LLVM
deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty main
deb-src http://llvm.org/apt/trusty/ llvm-toolchain-trusty main
# 3.5
deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.5 main
deb-src http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.5 main
# 3.6
deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.6 main
deb-src http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.6 main
LLVMAPT
wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key|sudo apt-key add -
sudo apt-get update -y
sudo apt-get install -y clang-3.6 lldb-3.6 libc++-dev libc++abi-dev
If the script above doesnt work or you do not use ubuntu then please check this websites to download that library:
http://libcxx.llvm.org/
http://libcxx.llvm.org/docs/BuildingLibcxx.html
Clang compiles C language and Clang++ compiles C++. Those are different languages, so you need a separate compiler for each of them.
Some time ago I was having trouble with this as well. I tried linking loads of libraries (-lstdc++ etc), building stdlib from source, etc, but nothing worked. This was a judge problem until I realized that I had to use clang++.
So you too, you need clang++, not clang.
I have a basic C++ program in Eclipse CDT:
#include <iostream>
using namespace std;
int main()
{
std::cout << "Hello World!";
}
However, when I try to build it, I get an Exec Format Error. Here is the output produced by the compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o hey.o "..\\hey.cpp"
g++: error: spawn: Exec format error
I am using MinGW Toolchain. I am on 64-bit Windows, and I think that may have something to do with it. Would anyone know how to get this program running?
Edit
Running the exact command in command prompt in the directory where my source file is works just fine, without throwing errors, but it still doesn't work in Eclipse
So, I have fixed this myself by installing the 64-bit version of MinGW (http://sourceforge.net/projects/mingw-w64/). It now compiles and builds noramlly
I try to compile and use clang from svn trunk. I basically try to follow the directions here:
svn co -q http://llvm.org/svn/llvm-project/llvm/trunk llvm
svn co -q http://llvm.org/svn/llvm-project/cfe/trunk llvm/tools/clang
svn co -q http://llvm.org/svn/llvm-project/clang-tools-extra/trunk llvm/tools/clang/tools/extra
svn co -q http://llvm.org/svn/llvm-project/compiler-rt/trunk llvm/projects/compiler-rt
mkdir llvm_build_release
cd llvm_build_release
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$HOME/usr/local -DLLVM_TARGETS_TO_BUILD=host ../llvm
make -j12
make install
Above, I configure clang to be installed in the custom location ~/usr/local since I want to be able to play with it without changing my default environment.
I then create a simple test.cpp:
#include <iostream>
int main(int argc, const char* argv[]){
std::cout << "Hello world\n";
return 0;
}
and try to compile it:
~/usr/local/bin/clang++ test.cpp -o test
but get the error message:
test.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^
1 error generated.
(using the system version of clang, the same compilation works fine).
If I manually enter which standard library to use, it does work
~/usr/local/bin/clang++ -std=c++11 -stdlib=libstdc++ -I/usr/include/c++/4.2.1/ -L/usr/lib test.cpp -o test
The question is: How do I configure, compile and install clang from source so that I do not have to enter these standard library settings, but instead can just enter the ordinary ~/usr/local/bin/clang++ test.cpp -o test? I have macports installed, with its version of the standard libraries and the include files, if that helps.