I wrote the following simple C++ program:
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World" << endl;
return 0;
}
When I compile this with g++, it works perfectly. When I try to compile with Clang++, I get the following error:
main.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
Running with the -v
parameter, I see the following:
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/backward"
ignoring nonexistent directory "/include"
ignoring duplicate directory "/usr/include/clang/6.0.0/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++
/usr/include/clang/6.0.0/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
Looking into these folders individually, I found that in /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++
(or, more concisely, in /usr/include/c++
) I have the following directories:
drwxr-xr-x 5 root root 4.0K Feb 4 09:38 .
drwxr-xr-x 101 root root 20K Feb 4 12:22 ..
drwxr-xr-x 12 root root 12K May 24 2018 5
drwxr-xr-x 12 root root 12K Oct 9 14:53 7
drwxr-xr-x 5 root root 4.0K Feb 4 09:38 v1
lrwxrwxrwx 1 root root 1 Apr 11 2018 5.5.0 -> 5
lrwxrwxrwx 1 root root 1 Apr 15 2018 7.3.0 -> 7
Within each of the 5
, 7
, and v1
directories there exists a file called iostream
Also in /usr/include/x86_64-linux-gnu
there exists a c++
directory which looks exactly like this one (with 5
, 7
, 5.5.0
, and 7.3.0
directories).
Also in /usr/include
there exists a c++
directory which looks exactly like the two above
I’m not sure how my dev environment became such a mess, but at this point I would just like to know how to fix it so that Clang++ will successfully find one of these 9 instances of iostream
instead of throwing an error that it doesn’t exist. Do I need to add an environment variable to tell Clang where to look? Do I need to pass a command-line parameter to tell Clang to search recursively?
Update (1)
When I try building with libc++
I get the following error:
$> clang++ -stdlib=libc++ main.cpp
/usr/bin/ld: cannot find -lc++abi
clang: error: linker command failed with exit code 1 (use -v to see invocation)
When I try building with the include path manually overridden, I get the following error:
$> clang++ -isystem /usr/include/c++/7 -isystem /usr/include/x86_64-linux-gnu/c++/7 main.cpp
/usr/bin/ld: cannot find -lstdc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)
When I try both, I get the following (incredibly large) error:
$> clang++ -isystem /usr/include/c++/7 -isystem /usr/include/x86_64-linux-gnu/c++/7 -stdlib=libc++ main.cpp
In file included from main.cpp:1:
In file included from /usr/include/c++/7/iostream:39:
In file included from /usr/include/c++/7/ostream:38:
In file included from /usr/include/c++/7/ios:42:
In file included from /usr/include/c++/7/bits/ios_base.h:41:
In file included from /usr/include/c++/7/bits/locale_classes.h:40:
In file included from /usr/include/c++/7/string:52:
In file included from /usr/include/c++/7/bits/basic_string.h:6352:
In file included from /usr/include/c++/7/ext/string_conversions.h:41:
In file included from /usr/include/c++/7/cstdlib:77:
/usr/include/c++/7/bits/std_abs.h:56:3: error: declaration conflicts with target of using declaration already in scope
abs(long __i) { return __builtin_labs(__i); }
^
/usr/include/c++/v1/stdlib.h:111:44: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY long abs( long __x) _NOEXCEPT {return labs(__x);}
^
/usr/include/c++/7/bits/std_abs.h:52:11: note: using declaration
using ::abs;
^
/usr/include/c++/7/bits/std_abs.h:61:3: error: declaration conflicts with target of using declaration already in scope
abs(long long __x) { return __builtin_llabs (__x); }
^
/usr/include/c++/v1/stdlib.h:113:44: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);}
^
/usr/include/c++/7/bits/std_abs.h:52:11: note: using declaration
using ::abs;
^
In file included from main.cpp:1:
In file included from /usr/include/c++/7/iostream:39:
In file included from /usr/include/c++/7/ostream:38:
In file included from /usr/include/c++/7/ios:42:
In file included from /usr/include/c++/7/bits/ios_base.h:41:
In file included from /usr/include/c++/7/bits/locale_classes.h:40:
In file included from /usr/include/c++/7/string:52:
In file included from /usr/include/c++/7/bits/basic_string.h:6352:
In file included from /usr/include/c++/7/ext/string_conversions.h:41:
/usr/include/c++/7/cstdlib:177:3: error: declaration conflicts with target of using declaration already in scope
div(long __i, long __j) { return ldiv(__i, __j); }
^
/usr/include/c++/v1/stdlib.h:116:42: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY ldiv_t div( long __x, long __y) _NOEXCEPT {return ldiv(__x, __y);}
^
/usr/include/c++/7/cstdlib:145:11: note: using declaration
using ::div;
^
As a reminder, I’m literally just trying to compile Hello, World
I also tried uninstalling and re-installing Clang with the following command:
$> sudo apt-get purge --auto-remove clang
$> sudo apt-get update
$> sudo apt-get install clang
This had no effect. I’m running Ubuntu 18.04 and I have no idea what’s wrong or where to start with fixing it. My build environment is in shambles.
If possible I would like to get Clang working instead of falling back to using G++, because my IDE seems to be automatically detecting Clang and using it for syntax checking. This means that every C++ program I’ve written has one fatal error on line one («iostream not found») and the rest of the file goes unchecked because that first one is a fatal error.
Update (2)
I’ve tried installing a few more packages from the Ubuntu apt repository with no luck:
$> sudo apt-get install libc++1 libc++1-9 libc++abi1 libc++abi1-9 llvm-9 llvm-9-dev
$> clang++ -isystem /usr/include/c++/7 -isystem /usr/include/x86_64-linux-gnu/c++/7 -stdlib=libc++ main.cpp
/usr/bin/ld: cannot find -lc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I also tried sudo apt-get install lc++1
only to find this is an entirely unrelated package.
Update (3)
I spent several more hours trying to resolve this, installing multiple packages both from apt and from source, trying different versions of various tools, manually copying in libraries from other sources, and even hopped onto the Clang IRC and spoke to several very knowledgeable developers directly.
No one was able to figure out what’s wrong with my laptop, and nothing I did ever got it working.
Unfortunately I won’t still have this laptop in another two weeks, so I’ll likely need to close this issue as «cannot reproduce» — because once the laptop is gone I will have no way of replicating the broken development environment.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Comments
Hi
I have a C++ code and when I try to run:
clang -O -c filename.cpp
I get:
fatal error: ‘iostream’ file not found
#include
^~~~~~~~~~
1 error generated.
If I try to include the path to iostream like:
clang -O -c filename.cpp -I/riscv-llvm/riscv/_install/riscv64-unknown-elf/include/c++/8.2.0
then I get another file not found:
fatal error: ‘bits/c++config.h’ file not found
#include <bits/c++config.h>
^~~~~~~~~~~~~~~~~~
1 error generated.
I found the bit folder to be empty. Do you have any clue on what is happening here?
Thanks
Here is how I fixed it.
I included c++/9.2.0
and c++/9.2.0/riscv64-unknown-elf
with clang++
and able to compile cpp
file to binary.
To check if clang++
is using right flags and directories, use -v
flag at the end of command line to print verbose trace.
Digging deeper in clang repo, C++ support is not tested. I didn’t see any tests with .cpp
extension. The fact that you need gnu linker makes me think that C++ feature is seeing the same fate too
2 participants
After upgrade to 14.04 from 12.04 clang++ stopped working.
$ cat test.cpp
#include <iostream>
int main()
{
std::cout << "Hello World" << std::endl;
return 0;
}
$ clang++ test.cpp
test.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^
1 error generated
Installed with apt-get install clag-3.5
same happened with clang-3.4
Thanks
asked Aug 27, 2014 at 16:37
4
I found to resolve this issue that after installing libstdc++-4.8-dev
package, I need to specify the include paths and lib path to the clang++ like this.
clang++ -I/usr/include/c++/4.8/ -I/usr/include/x86_64-linux-gnu/c++/4.8 -L /usr/lib/gcc/x86_64-linux-gnu/4.8 test.cpp -o test
answered Jan 2, 2018 at 16:02
1
Your code works for me. Make sure you have libstdc++-dev installed. It’s a virtual package, and in my case (Ubuntu 14.04.2 LTS) having 4.8 works.
sudo apt-get install libstdc++-4.8-dev
answered May 18, 2015 at 20:07
m0j0m0j0
1356 bronze badges
2
I have also been troubled by this problem for a long time.You should try to delete the folder(cd /usr/lib/gcc/aarch64-linux-gnu/8). The reason why clang++ can’t work is this folder doesn’t contain libstdc++.a.
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/5
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/5.5.0
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/6
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/6.5.0
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/5.5.0
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6.5.0
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7.3.0
Selected GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
check all the folders in /usr/lib/gcc/aarch64-linux-gnu/
clang++ will choose the last one,make sure there is the libstdc++.a in the last one
I found that clang was using the installation in /usr/lib/gcc/x86_64-linux-gnu/8
(using clang++ -v
), and indeed this did not contain the file libstdc++.a
. Rather than delete the whole directory as suggested by another answer, I was able to just install libstdc++-8-dev
.
I’m on Ubuntu 18.04; gcc was already installed.
Tags:
Linux
C++
Clang
Clang++
Related
0
1
Всем привет.
Понадобилось скомпилировать С++ файл (С++11) с помощью clang. Запускаю, получаю:
$ clang -std=c++11 -stdlib=libc++ file.cpp
file.cpp:1:9: fatal error: 'iostream' file not found
#include<iostream>
^
1 error generated
Почему он не может найти заголовочный файл? Как это победить?
clang-3.6.2, gcc-4.9.3:
$ emerge -pv --nodeps clang gcc llvm
These are the packages that would be merged, in order:
[ebuild R ] sys-devel/clang-3.6.2-r100:0/3.6::gentoo USE="python static-analyzer -debug -multitarget" 0 KiB
[ebuild R ] sys-devel/gcc-4.9.3:4.9::gentoo USE="cxx fortran nls nptl objc objc++ objc-gc openmp sanitize (-altivec) -awt -cilk -debug -doc (-fixed-point) -gcj -go -graphite (-hardened) (-libssp) (-multilib) (-multislot) -nopie -nossp -regression-test -vanilla" 23 KiB
[ebuild R ] sys-devel/llvm-3.6.2:0/3.6::gentoo USE="clang libffi ncurses python static-analyzer xml -debug -doc -gold -libedit -multitarget -ocaml {-test}" PYTHON_TARGETS="python2_7 -pypy" VIDEO_CARDS="-radeon" 0 KiB
Total: 3 packages (3 reinstalls), Size of downloads: 23 KiB
Ранее я ставил связанный вопрос.
У меня есть следующая программа, извлеченная из большого проекта в моей Mac OS
#include <iostream>
int main(){
std::cout<<"hello"<<std::endl;
return 0;
}
Компиляция с использованием Clang завершается с ошибкой:
$ clang test.cpp
test.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^
1 error generated.
Для информации,
А) Я уже установил инструменты командной строки xcode, используя xcodeselect —install. Но кажется, что iostream не находится в поисковом пути по умолчанию clang.
Б) Использование g ++ вместо clang компилирует программу. Но в моей проблеме мне не разрешено использовать другой компилятор, кроме clang, или изменять исходную программу.
C) Я могу увидеть методы обхода, например, путем настройки пути поиска в .bashrc или с помощью некоторой символической ссылки и т. Д. Но я неохотно использую их, потому что кажется, что у меня есть проблема с установкой моего Clang и настройка пути только помогает избежать одной из этих проблем пути.
-3
Решение
clang
а также clang++
делать разные вещи. Если вы хотите скомпилировать код C ++, вам нужно использовать clang++
В качестве альтернативы вы можете вызвать компилятор c ++ напрямую, явно указав имя языка:
clang -x=c++
1
Другие решения
Других решений пока нет …
I wrote the following simple C++ program:
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World" << endl;
return 0;
}
When I compile this with g++, it works perfectly. When I try to compile with Clang++, I get the following error:
main.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
Running with the -v
parameter, I see the following:
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/backward"
ignoring nonexistent directory "/include"
ignoring duplicate directory "/usr/include/clang/6.0.0/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++
/usr/include/clang/6.0.0/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
Looking into these folders individually, I found that in /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++
(or, more concisely, in /usr/include/c++
) I have the following directories:
drwxr-xr-x 5 root root 4.0K Feb 4 09:38 .
drwxr-xr-x 101 root root 20K Feb 4 12:22 ..
drwxr-xr-x 12 root root 12K May 24 2018 5
drwxr-xr-x 12 root root 12K Oct 9 14:53 7
drwxr-xr-x 5 root root 4.0K Feb 4 09:38 v1
lrwxrwxrwx 1 root root 1 Apr 11 2018 5.5.0 -> 5
lrwxrwxrwx 1 root root 1 Apr 15 2018 7.3.0 -> 7
Within each of the 5
, 7
, and v1
directories there exists a file called iostream
Also in /usr/include/x86_64-linux-gnu
there exists a c++
directory which looks exactly like this one (with 5
, 7
, 5.5.0
, and 7.3.0
directories).
Also in /usr/include
there exists a c++
directory which looks exactly like the two above
I’m not sure how my dev environment became such a mess, but at this point I would just like to know how to fix it so that Clang++ will successfully find one of these 9 instances of iostream
instead of throwing an error that it doesn’t exist. Do I need to add an environment variable to tell Clang where to look? Do I need to pass a command-line parameter to tell Clang to search recursively?
Update (1)
When I try building with libc++
I get the following error:
$> clang++ -stdlib=libc++ main.cpp
/usr/bin/ld: cannot find -lc++abi
clang: error: linker command failed with exit code 1 (use -v to see invocation)
When I try building with the include path manually overridden, I get the following error:
$> clang++ -isystem /usr/include/c++/7 -isystem /usr/include/x86_64-linux-gnu/c++/7 main.cpp
/usr/bin/ld: cannot find -lstdc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)
When I try both, I get the following (incredibly large) error:
$> clang++ -isystem /usr/include/c++/7 -isystem /usr/include/x86_64-linux-gnu/c++/7 -stdlib=libc++ main.cpp
In file included from main.cpp:1:
In file included from /usr/include/c++/7/iostream:39:
In file included from /usr/include/c++/7/ostream:38:
In file included from /usr/include/c++/7/ios:42:
In file included from /usr/include/c++/7/bits/ios_base.h:41:
In file included from /usr/include/c++/7/bits/locale_classes.h:40:
In file included from /usr/include/c++/7/string:52:
In file included from /usr/include/c++/7/bits/basic_string.h:6352:
In file included from /usr/include/c++/7/ext/string_conversions.h:41:
In file included from /usr/include/c++/7/cstdlib:77:
/usr/include/c++/7/bits/std_abs.h:56:3: error: declaration conflicts with target of using declaration already in scope
abs(long __i) { return __builtin_labs(__i); }
^
/usr/include/c++/v1/stdlib.h:111:44: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY long abs( long __x) _NOEXCEPT {return labs(__x);}
^
/usr/include/c++/7/bits/std_abs.h:52:11: note: using declaration
using ::abs;
^
/usr/include/c++/7/bits/std_abs.h:61:3: error: declaration conflicts with target of using declaration already in scope
abs(long long __x) { return __builtin_llabs (__x); }
^
/usr/include/c++/v1/stdlib.h:113:44: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);}
^
/usr/include/c++/7/bits/std_abs.h:52:11: note: using declaration
using ::abs;
^
In file included from main.cpp:1:
In file included from /usr/include/c++/7/iostream:39:
In file included from /usr/include/c++/7/ostream:38:
In file included from /usr/include/c++/7/ios:42:
In file included from /usr/include/c++/7/bits/ios_base.h:41:
In file included from /usr/include/c++/7/bits/locale_classes.h:40:
In file included from /usr/include/c++/7/string:52:
In file included from /usr/include/c++/7/bits/basic_string.h:6352:
In file included from /usr/include/c++/7/ext/string_conversions.h:41:
/usr/include/c++/7/cstdlib:177:3: error: declaration conflicts with target of using declaration already in scope
div(long __i, long __j) { return ldiv(__i, __j); }
^
/usr/include/c++/v1/stdlib.h:116:42: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY ldiv_t div( long __x, long __y) _NOEXCEPT {return ldiv(__x, __y);}
^
/usr/include/c++/7/cstdlib:145:11: note: using declaration
using ::div;
^
As a reminder, I’m literally just trying to compile Hello, World
I also tried uninstalling and re-installing Clang with the following command:
$> sudo apt-get purge --auto-remove clang
$> sudo apt-get update
$> sudo apt-get install clang
This had no effect. I’m running Ubuntu 18.04 and I have no idea what’s wrong or where to start with fixing it. My build environment is in shambles.
If possible I would like to get Clang working instead of falling back to using G++, because my IDE seems to be automatically detecting Clang and using it for syntax checking. This means that every C++ program I’ve written has one fatal error on line one («iostream not found») and the rest of the file goes unchecked because that first one is a fatal error.
Update (2)
I’ve tried installing a few more packages from the Ubuntu apt repository with no luck:
$> sudo apt-get install libc++1 libc++1-9 libc++abi1 libc++abi1-9 llvm-9 llvm-9-dev
$> clang++ -isystem /usr/include/c++/7 -isystem /usr/include/x86_64-linux-gnu/c++/7 -stdlib=libc++ main.cpp
/usr/bin/ld: cannot find -lc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I also tried sudo apt-get install lc++1
only to find this is an entirely unrelated package.
Update (3)
I spent several more hours trying to resolve this, installing multiple packages both from apt and from source, trying different versions of various tools, manually copying in libraries from other sources, and even hopped onto the Clang IRC and spoke to several very knowledgeable developers directly.
No one was able to figure out what’s wrong with my laptop, and nothing I did ever got it working.
Unfortunately I won’t still have this laptop in another two weeks, so I’ll likely need to close this issue as «cannot reproduce» — because once the laptop is gone I will have no way of replicating the broken development environment.
Я написал следующую простую программу на C++:
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World" << endl;
return 0;
}
Когда я скомпилирую это с помощью g++, он отлично работает. Когда я пытаюсь скомпилировать с помощью Clang++, я получаю следующую ошибку:
main.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
Запуская с параметром -v, я вижу следующее:
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/backward"
ignoring nonexistent directory "/include"
ignoring duplicate directory "/usr/include/clang/6.0.0/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++
/usr/include/clang/6.0.0/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
Заглянув в эти папки по отдельности, я обнаружил, что в /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++ (точнее, в /usr/include/c++) у меня есть следующие каталоги:
drwxr-xr-x 5 root root 4.0K Feb 4 09:38 .
drwxr-xr-x 101 root root 20K Feb 4 12:22 ..
drwxr-xr-x 12 root root 12K May 24 2018 5
drwxr-xr-x 12 root root 12K Oct 9 14:53 7
drwxr-xr-x 5 root root 4.0K Feb 4 09:38 v1
lrwxrwxrwx 1 root root 1 Apr 11 2018 5.5.0 -> 5
lrwxrwxrwx 1 root root 1 Apr 15 2018 7.3.0 -> 7
В каждом из каталогов 5, 7 и v1 существует файл с именем iostream.
Также в /usr/include/x86_64-linux-gnu существует каталог c++, который выглядит точно так же (с каталогами 5, 7, 5.5.0 и 7.3.0).
Также в /usr/include существует каталог c++, который выглядит точно так же, как два выше.
Я не уверен, как моя среда разработки превратилась в такой беспорядок, но на данный момент я просто хотел бы знать, как это исправить, чтобы Clang++ успешно находил один из этих 9 экземпляров iostream вместо того, чтобы выдавать ошибку, которую он не делает. т существует. Нужно ли добавлять переменную среды, чтобы сообщить Clang, где искать? Нужно ли передавать параметр командной строки, чтобы сообщить Clang о рекурсивном поиске?
Обновление (1)
Когда я пытаюсь собрать с помощью libc++, я получаю следующую ошибку:
$> clang++ -stdlib=libc++ main.cpp
/usr/bin/ld: cannot find -lc++abi
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Когда я пытаюсь выполнить сборку с переопределением пути включения вручную, я получаю следующую ошибку:
$> clang++ -isystem /usr/include/c++/7 -isystem /usr/include/x86_64-linux-gnu/c++/7 main.cpp
/usr/bin/ld: cannot find -lstdc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Когда я пробую оба, я получаю следующую (невероятно большую) ошибку:
$> clang++ -isystem /usr/include/c++/7 -isystem /usr/include/x86_64-linux-gnu/c++/7 -stdlib=libc++ main.cpp
In file included from main.cpp:1:
In file included from /usr/include/c++/7/iostream:39:
In file included from /usr/include/c++/7/ostream:38:
In file included from /usr/include/c++/7/ios:42:
In file included from /usr/include/c++/7/bits/ios_base.h:41:
In file included from /usr/include/c++/7/bits/locale_classes.h:40:
In file included from /usr/include/c++/7/string:52:
In file included from /usr/include/c++/7/bits/basic_string.h:6352:
In file included from /usr/include/c++/7/ext/string_conversions.h:41:
In file included from /usr/include/c++/7/cstdlib:77:
/usr/include/c++/7/bits/std_abs.h:56:3: error: declaration conflicts with target of using declaration already in scope
abs(long __i) { return __builtin_labs(__i); }
^
/usr/include/c++/v1/stdlib.h:111:44: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY long abs( long __x) _NOEXCEPT {return labs(__x);}
^
/usr/include/c++/7/bits/std_abs.h:52:11: note: using declaration
using ::abs;
^
/usr/include/c++/7/bits/std_abs.h:61:3: error: declaration conflicts with target of using declaration already in scope
abs(long long __x) { return __builtin_llabs (__x); }
^
/usr/include/c++/v1/stdlib.h:113:44: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);}
^
/usr/include/c++/7/bits/std_abs.h:52:11: note: using declaration
using ::abs;
^
In file included from main.cpp:1:
In file included from /usr/include/c++/7/iostream:39:
In file included from /usr/include/c++/7/ostream:38:
In file included from /usr/include/c++/7/ios:42:
In file included from /usr/include/c++/7/bits/ios_base.h:41:
In file included from /usr/include/c++/7/bits/locale_classes.h:40:
In file included from /usr/include/c++/7/string:52:
In file included from /usr/include/c++/7/bits/basic_string.h:6352:
In file included from /usr/include/c++/7/ext/string_conversions.h:41:
/usr/include/c++/7/cstdlib:177:3: error: declaration conflicts with target of using declaration already in scope
div(long __i, long __j) { return ldiv(__i, __j); }
^
/usr/include/c++/v1/stdlib.h:116:42: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY ldiv_t div( long __x, long __y) _NOEXCEPT {return ldiv(__x, __y);}
^
/usr/include/c++/7/cstdlib:145:11: note: using declaration
using ::div;
^
Напоминаем, Я буквально просто пытаюсь скомпилировать Hello, World
Я также попытался удалить и переустановить Clang с помощью следующей команды:
$> sudo apt-get purge --auto-remove clang
$> sudo apt-get update
$> sudo apt-get install clang
Это не имело никакого эффекта. Я использую Ubuntu 18.04 и понятия не имею, что не так и с чего начать, чтобы исправить это. Моя среда сборки находится в упадке.
Если возможно, я бы хотел, чтобы Clang работал, а не возвращался к использованию G++, потому что моя IDE, похоже, автоматически обнаруживает Clang и использует его для проверки синтаксиса. Это означает, что каждая программа на C++, которую я написал, имеет одну фатальную ошибку в первой строке («iostream не найден»), а остальная часть файла не проверяется, потому что первая ошибка является фатальной.
Обновление (2)
Я безуспешно пытался установить еще несколько пакетов из репозитория Ubuntu apt:
$> sudo apt-get install libc++1 libc++1-9 libc++abi1 libc++abi1-9 llvm-9 llvm-9-dev
$> clang++ -isystem /usr/include/c++/7 -isystem /usr/include/x86_64-linux-gnu/c++/7 -stdlib=libc++ main.cpp
/usr/bin/ld: cannot find -lc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Я также попробовал sudo apt-get install lc++1, но обнаружил, что это пакет совершенно не связанный.
Обновление (3)
Я потратил еще несколько часов, пытаясь решить эту проблему, устанавливая несколько пакетов как из apt, так и из исходного кода, пробуя разные версии различных инструментов, вручную копируя библиотеки из других источников и даже запрыгнув на Clang IRC и напрямую поговорив с несколькими очень знающими разработчиками. .
Никто не мог понять, что не так с моим ноутбуком, и ничего из того, что я делал, никогда не заставляло его работать.
К сожалению, через две недели у меня не будет этого ноутбука, поэтому мне, вероятно, придется закрыть эту проблему как «невозможно воспроизвести», потому что, как только ноутбук исчезнет, у меня не будет возможности воспроизвести сломанную среду разработки.
Я написал следующую простую программу на C ++:
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World" << endl;
return 0;
}
Когда я компилирую это с g ++, это работает отлично. Когда я пытаюсь скомпилировать с Clang ++, я получаю следующую ошибку:
main.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
Работая с параметром -v
, я вижу следующее:
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/backward"
ignoring nonexistent directory "/include"
ignoring duplicate directory "/usr/include/clang/6.0.0/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++
/usr/include/clang/6.0.0/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
Рассматривая эти папки по отдельности, я обнаружил, что в /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++
(или, более кратко, в /usr/include/c++
) у меня есть следующие каталоги:
drwxr-xr-x 5 root root 4.0K Feb 4 09:38 .
drwxr-xr-x 101 root root 20K Feb 4 12:22 ..
drwxr-xr-x 12 root root 12K May 24 2018 5
drwxr-xr-x 12 root root 12K Oct 9 14:53 7
drwxr-xr-x 5 root root 4.0K Feb 4 09:38 v1
lrwxrwxrwx 1 root root 1 Apr 11 2018 5.5.0 -> 5
lrwxrwxrwx 1 root root 1 Apr 15 2018 7.3.0 -> 7
В каждом из каталогов 5
, 7
и v1
существует файл с именем iostream
Также в /usr/include/x86_64-linux-gnu
существует каталог c++
, который выглядит точно так же (с каталогами 5
, 7
, 5.5.0
и 7.3.0
,
Также в /usr/include
существует каталог c++
, который выглядит точно так же, как два выше
Я не уверен, как моя среда разработки превратилась в такой беспорядок, но на данный момент я просто хотел бы знать, как это исправить, чтобы Clang ++ успешно нашел один из этих 9 экземпляров iostream
вместо того, чтобы выдавать ошибку что его не существует. Нужно ли добавлять переменную окружения, чтобы указать Clang, где искать? Нужно ли передавать параметр командной строки, чтобы сказать Clang рекурсивный поиск?
Обновление (1)
Когда я пытаюсь построить с libc++
, я получаю следующую ошибку:
$> clang++ -stdlib=libc++ main.cpp
/usr/bin/ld: cannot find -lc++abi
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Когда я пытаюсь построить с включенным вручную путем включения, я получаю следующую ошибку:
$> clang++ -isystem /usr/include/c++/7 -isystem /usr/include/x86_64-linux-gnu/c++/7 main.cpp
/usr/bin/ld: cannot find -lstdc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Когда я пробую оба, я получаю следующую (невероятно большую) ошибку:
$> clang++ -isystem /usr/include/c++/7 -isystem /usr/include/x86_64-linux-gnu/c++/7 -stdlib=libc++ main.cpp
In file included from main.cpp:1:
In file included from /usr/include/c++/7/iostream:39:
In file included from /usr/include/c++/7/ostream:38:
In file included from /usr/include/c++/7/ios:42:
In file included from /usr/include/c++/7/bits/ios_base.h:41:
In file included from /usr/include/c++/7/bits/locale_classes.h:40:
In file included from /usr/include/c++/7/string:52:
In file included from /usr/include/c++/7/bits/basic_string.h:6352:
In file included from /usr/include/c++/7/ext/string_conversions.h:41:
In file included from /usr/include/c++/7/cstdlib:77:
/usr/include/c++/7/bits/std_abs.h:56:3: error: declaration conflicts with target of using declaration already in scope
abs(long __i) { return __builtin_labs(__i); }
^
/usr/include/c++/v1/stdlib.h:111:44: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY long abs( long __x) _NOEXCEPT {return labs(__x);}
^
/usr/include/c++/7/bits/std_abs.h:52:11: note: using declaration
using ::abs;
^
/usr/include/c++/7/bits/std_abs.h:61:3: error: declaration conflicts with target of using declaration already in scope
abs(long long __x) { return __builtin_llabs (__x); }
^
/usr/include/c++/v1/stdlib.h:113:44: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);}
^
/usr/include/c++/7/bits/std_abs.h:52:11: note: using declaration
using ::abs;
^
In file included from main.cpp:1:
In file included from /usr/include/c++/7/iostream:39:
In file included from /usr/include/c++/7/ostream:38:
In file included from /usr/include/c++/7/ios:42:
In file included from /usr/include/c++/7/bits/ios_base.h:41:
In file included from /usr/include/c++/7/bits/locale_classes.h:40:
In file included from /usr/include/c++/7/string:52:
In file included from /usr/include/c++/7/bits/basic_string.h:6352:
In file included from /usr/include/c++/7/ext/string_conversions.h:41:
/usr/include/c++/7/cstdlib:177:3: error: declaration conflicts with target of using declaration already in scope
div(long __i, long __j) { return ldiv(__i, __j); }
^
/usr/include/c++/v1/stdlib.h:116:42: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY ldiv_t div( long __x, long __y) _NOEXCEPT {return ldiv(__x, __y);}
^
/usr/include/c++/7/cstdlib:145:11: note: using declaration
using ::div;
^
Напоминаю, что я буквально пытаюсь скомпилировать Hello, World .
Я также попытался удалить и переустановить Clang с помощью следующей команды:
$> sudo apt-get purge --auto-remove clang
$> sudo apt-get update
$> sudo apt-get install clang
Это не имело никакого эффекта. Я использую Ubuntu 18.04 и понятия не имею, что не так или с чего начать, чтобы исправить это. Моя среда сборки находится в руинах.
Если возможно, я бы хотел, чтобы Clang работал, а не возвращался к использованию G ++, потому что моя IDE, похоже, автоматически обнаруживает Clang и использует его для проверки синтаксиса. Это означает, что каждая написанная мною программа C ++ имеет одну фатальную ошибку в первой строке («iostream not found»), а остальная часть файла не проверяется, потому что первая — фатальная ошибка.
Обновление (2)
Я попытался установить еще несколько пакетов из репозитория Ubuntu apt, но безуспешно:
$> sudo apt-get install libc++1 libc++1-9 libc++abi1 libc++abi1-9 llvm-9 llvm-9-dev
$> clang++ -isystem /usr/include/c++/7 -isystem /usr/include/x86_64-linux-gnu/c++/7 -stdlib=libc++ main.cpp
/usr/bin/ld: cannot find -lc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Я также попытался sudo apt-get install lc++1
найти только совершенно не связанный пакет.
Обновление (3)
Я потратил еще несколько часов, пытаясь решить эту проблему, устанавливая несколько пакетов как из apt, так и из исходных текстов, пробуя разные версии различных инструментов, вручную копируя в библиотеки из других источников, и даже переходил на Clang IRC и общался с несколькими очень хорошо осведомленными разработчиками напрямую. ,
Никто не смог понять, что случилось с моим ноутбуком, и ничто из того, что я делал, не заставляло его работать.
К сожалению, через две недели у меня все еще не будет этого ноутбука, поэтому мне, вероятно, придется закрыть эту проблему, поскольку она «не может воспроизвести» — потому что после того, как ноутбук уйдет, у меня не будет возможности воспроизвести испорченную среду разработки.