I have set up an environment for autocompletion in Emacs, using clang 2.8 as the parser. It works well, but relies on saving the currently edited buffer to file before completion. This is slow, so I am trying to get clang to parse a file given to it via stdin instead, without luck so far.
The command line I feed clang when parsing a file is as follows:
clang -cc1 -fsyntax-only -Iinclude/ -code-completion-at foo.cpp:10:20 foo.cpp
This works well. But attempts to read from stdin fail. I've tried this:
cat foo.cpp | clang -xc++ -cc1 -fsyntax-only -Iinclude/ -code-completion-at -:10:20 -
But that makes clang terminate without making any completions and prints the warnings:
clang: warning: argument unused during compilation: '-cc1'
clang: warning: argument unused during compilation: '-code-completion-at'
clang: warning: argument unused during compilation: '-:10:20'
Any ideas?
Does it work if you specify -cc1 before -x c++?
Related
I got these errors trying to execute mingw32-make:
g++: error: unrecognized command-line option '--cflags' g++: error: unrecognized command-line option '--libs'`
The makefile is the following:
all:
g++ fitscli.cpp vipsoperations.cpp fits.cpp ConsoleTable.cpp `pkg-config vips-cpp --cflags --libs` -lcfitsio -ltiff -o fitscli
After some research there was a suggestion to delete '--cflags' and '--libs` from the code, and I did it.
I know is that maybe the compiler g++ is not having able the options '--cflags' and '--libs`
I also tried to change to gcc compiler, but doesn´t work.
I am working on windows 11, with Msys URCT64
When I deleted the lines suggested, is causing another compilation error, so I want to know how to fix the flags issue without deleted them from the code.
Thanks.
The backticks ` ` don't seem to work properly in mingw32-make (because it uses CMD as the shell, which doesn't support them).
Use make instead (install with pacman -S make), which uses Bash.
Right now I am using the following line:
clang -Xclang -load -Xclang ../pass/pass.so -O2 -I../library/src/include/ -L../library/src/debug/ -DTAG_BITS=15 -lib1 -lib2 example.ll -o example
where I'm using my pass and example.ll is an example file that I linked with a runtime file (needed by the pass) using llvm-link. It does compile, but clang is skipping the libraries and using the built-ins instead:
clang: argument unused during compilation: '-I ../library/src/include/' [-Wunused-command-line-argument]
Why is the library being skipped? If I'm doing this wrong is there some other way I could compile the linked modules?
You've asked clang to compile example.ll which is an LLVM IR text file, and no other files. LLVM IR text doesn't have C-style #include statements, so the -I flag telling clang to look in your ../library/src/include/ directory to resolve files in a #include directive can't affect the compilation.
I want to use distcc to compile code from my Mac to a bunch of Linux hosts, but I can't figure out how to make everything "line up". I've successfully used distcc from Mac to Mac, so I have a general idea of how to set things up.
I'm using Clang 4.0 and have it installed and working on both Mac and Linux. The following command compiles fine without the distcc at the beginning, but after adding distcc, I get the following issues:
distcc /Users/xaxxon/Downloads/clang+llvm-4.0.0-x86_64-apple-darwin/bin/clang++ -I/usr/local/include -I/Users/xaxxon/v8toolkit/./include -I/Users/xaxxon/v8/include -stdlib=libc++ -g -Werror=return-type -g -std=gnu++1z -o CMakeFiles/v8toolkit_static.dir/src/v8toolkit.cpp.o -c /Users/xaxxon/v8toolkit/src/v8toolkit.cpp
I'm not sure what compiler is being picked up on Linux, nor do I know how to find out. It's possible it's picking up GCC instead of Clang.
My first concern is this:
clang: warning: argument unused during compilation: '-stdlib=libc++'
My first error is:
In file included from /Users/xaxxon/v8toolkit/src/v8toolkit.cpp:5:
In file included from /usr/include/assert.h:44:
In file included from /Users/xaxxon/Downloads/clang+llvm-4.0.0-x86_64-apple-darwin/bin/../include/c++/v1/stdlib.h:94:
/usr/include/stdlib.h:250:20: error: blocks support disabled - compile with -fblocks or pick a deployment target that supports them
int atexit_b(void (^)(void)) __attribute__((availability(macosx,introduced=10.6)));
The next error I get (which becomes the first error if I manually add -fblocks to the compilation command (which isn't needed on a native Mac build) is:
/Users/xaxxon/Downloads/clang+llvm-4.0.0-x86_64-apple-darwin/bin/../include/c++/v1/__tuple:289:13: error: unknown type name '__type_pack_element'
typedef __type_pack_element<_Ip, _Types...> type;
^
/Users/xaxxon/Downloads/clang+llvm-4.0.0-x86_64-apple-darwin/bin/../include/c++/v1/__tuple:289:32: error: expected member name or ';' after declaration specifiers
typedef __type_pack_element<_Ip, _Types...> type;
~~~~~~~~~~~~~~~~~~~~~~~~~~~^
/Users/xaxxon/Downloads/clang+llvm-4.0.0-x86_64-apple-darwin/bin/../include/c++/v1/__tuple:356:43: error: use of undeclared identifier '__type_pack_element'
typename _ApplyFn::template __apply<__type_pack_element<_Idx, _Types...>>...
^
/Users/xaxxon/Downloads/clang+llvm-4.0.0-x86_64-apple-darwin/bin/../include/c++/v1/__tuple:357:6: error: expected a type
>;
I don't understand if I'm doing something fundamentally wrong or if there's something small I'm missing which is making the Linux compiler act differently.
I just made sure to have Clang on Linux in the same named directory and now am only getting the -fblocks and unused during compilation -stdlib=libc++ issues.
I can get everything to compile (albeit with warnings), but when it links, I get:
ld: warning: ignoring file CMakeFiles/v8toolkit_shared.dir/src/debugger.cpp.o, file was built for
unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the architecture being linked
(x86_64): CMakeFiles/v8toolkit_shared.dir/src/debugger.cpp.o
As long as you specify the -target flag, you can even cross-compile, because Clang is a native cross compiler.
Cross-compilation using Clang
Adding the -target flag fixes everything! In my case, for Mac OS X v10.11 (El Capitan), the target triple is:
-target x86_64-apple-darwin15.6.0
for a build command of:
distcc /Users/xaxxon/Downloads/clang+llvm-4.0.0-x86_64-apple-darwin/bin/clang++ -Dv8toolkit_shared_EXPORTS -I/usr/local/include -I/Users/xaxxon/v8toolkit/./include -isystem /Users/xaxxon/v8/include -stdlib=libc++ -g -Werror=return-type -target x86_64-apple-darwin15.6.0 -g -fPIC -std=gnu++1z -o CMakeFiles/v8toolkit_shared.dir/src/v8toolkit.cpp.o -c /Users/xaxxon/v8toolkit/src/v8toolkit.cpp
You can get the current host's target by typing clang -v:
$ clang -v
clang version 4.0.0 (tags/RELEASE_400/final)
Target: x86_64-apple-darwin15.6.0 <<==== THIS LINE HERE
Thread model: posix
InstalledDir: /Users/xaxxon/Downloads/clang+llvm-4.0.0-x86_64-apple-darwin/bin
The following CMake lines will grab (and print) the triple for the current machine:
# Get the target triple for the current host by calling clang -v and then stripping out the Target: value from its output. CMake regex syntax is quite limited.
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -v ERROR_VARIABLE CLANG_VERSION_INFO)
string(REGEX REPLACE ".*Target:[\r\n\t ]*([^\r\n\t]*).*Thread model.*" "\\1" TARGET_TRIPLE ${CLANG_VERSION_INFO})
message(STATUS "TARGET TRIPLE: '${TARGET_TRIPLE}' END")
Much thanks to #duskwuff and oftc.net #llvm for help figuring this out!
I have the following file foo.cpp:
#include <vector>
struct MyClass
{
std::vector<int> v;
};
It can be successfully compiled with clang (I'm using clang 3.3 on Ubuntu 13.04 32bit):
clang++ -c foo.cpp
Now I want to print AST:
clang++ -cc1 -ast-print foo.cpp
and I've got the following error
foo.cpp:1:10: fatal error: 'vector' file not found
#include <vector>
^
struct MyClass {
};
1 error generated.
It looks like clang++ -cc1 doesn't know about system include files etc.
I'm wondering how to set up includes for clang++ -cc1?
You need to set up the right include paths.
on my system I added
-I/usr/include/i386-linux-gnu/c++/4.8 -I/usr/include/c++/4.8
to the compiler flags. The first one was so that it could find
bits/c++config.h
Of course the 4.8 is due to the fact I am using a compiler compatible with g++-4.8
I also added
-std=c++11 -stdlib=libstdc++
as compiler options.
Hope this helps
It's a Frequently Asked Question
#john is correct. For posterity, the relevant portions of the FAQ are (with names tweaked to match the question) :
clang -cc1 is the frontend, clang is the driver. The driver invokes the frontend with options appropriate for your system. To see these options, run:
$ clang++ -### -c foo.cpp
Some clang command line options are driver-only options, some are frontend-only options. Frontend-only options are intended to be used only by clang developers. Users should not run clang -cc1 directly, because -cc1 options are not guaranteed to be stable.
If you want to use a frontend-only option (“a -cc1 option”), for example -ast-dump, then you need to take the clang -cc1 line generated by the driver and add the option you need. Alternatively, you can run clang -Xclang <option> ... to force the driver [to] pass <option> to clang -cc1.
I did the latter (-Xclang) for emitting precompiled headers:
/usr/bin/clang++ -x c++-header foo.hpp -Xclang -emit-pch -o foo.hpp.pch <other options>
^^^^^^^
Without the -Xclang, clang++ ignored the -emit-pch. When I tried -cc1, I had the same problem as the OP — clang++ accepted -emit-pch but didn't have the other options the driver normally provides.
I'm trying to compile C++11 code that declares a variable of type std::atomic_bool. This is on Mac OS 10.8.2 with clang:
clang --version
Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin12.2.0
Thread model: posix
clang complains about std::atomic_bool:
clang++ -c -stdlib=libc++ -msse4 -std=c++11 -Wno-unused-parameter -I. -o query.o query.cpp
In file included from query.cpp:1:
[...]
./threadutils.h:33:10: error: no type named 'atomic_bool' in namespace 'std'; did you mean 'atomic_long'?
std::atomic_bool work;
However, the same file compiles fine in an XCode project using the same compiler. So I assume I'm missing something in my manual compiler invocation.
I tried a few variations such as -std=c++0x and -std=gnu++11, to no avail.
I figured it out. Unfortunately I planted a false flag into my question: it didn't work in XCode either, I had a different version of the source file imported there.
The problem was that C++11 defines "a named type atomic_bool corresponding to the specified atomic<bool>", but clang doesn't support that.
Renaming the type from atomic_bool to atomic<bool> fixed it.
I found the same problem. In my case I resolved it by including atomic:
#include <atomic>
static std::atomic_bool varname;
After this, I could call g++ with std=c++11 on a Linux (Ubuntu) as well as compile on XCode.