LLVM equivalent of gcc -D macro definition on commandline - llvm

I am looking for LLVM (or clang) equivalent of gcc's -D flag which enables macro definition at commandline.
Any pointers would be great.

From clang --cc1 --help:
...
-D <macro>=<value> Define <macro> to <value> (or 1 if <value> omitted)
...
As a rule of thumb, assume that Clang emulates GCC, unless proven otherwise!

The default clang invocation is a gcc-like compiler driver, supporting the same options as gcc, including -D:
: ~$ cat test/z.c
int foo() {
return FOOBAR;
}
: ~$ clang -DFOOBAR -E -c test/z.c
# 1 "test/z.c"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 154 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "test/z.c" 2
int foo() {
return 1;
}
So if you want to replace gcc, just invoke clang. clang -cc1 invokes the front-end component of clang, not the generic compiler driver.

Related

Unable to install tezos-crypto due to compliation error in package tezos-stdlib-unix

I am trying to install the library tezos-crypto using Opam on Kubuntu 20.04. I am getting the following error:
<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[ERROR] The compilation of tezos-stdlib-unix failed at "/home/marc/.opam/opam-init/hooks/sandbox.sh build dune build -p
tezos-stdlib-unix -j 15".
#=== ERROR while compiling tezos-stdlib-unix.10.2 =============================#
# context 2.0.5 | linux/x86_64 | ocaml-base-compiler.4.11.1 | https://opam.ocaml.org#e0171a79
# path ~/.opam/default/.opam-switch/build/tezos-stdlib-unix.10.2
# command ~/.opam/opam-init/hooks/sandbox.sh build dune build -p tezos-stdlib-unix -j 15
# exit-code 1
# env-file ~/.opam/log/tezos-stdlib-unix-69301-e0ba4f.env
# output-file ~/.opam/log/tezos-stdlib-unix-69301-e0ba4f.out
### output ###
# [...]
# (cd _build/default && /home/marc/.opam/default/bin/ocamlc.opt -w -40 -open Tezos_error_monad -open Tezos_error_monad.TzLwtreslib -open Tezos_event_logging -open Tezos_stdlib -open Data_encoding -g -bin-annot -I src/lib_stdlib_unix/.tezos_stdlib_unix.objs/byte -I /home/marc/.opam/default/lib/angstrom -I /home/marc/.opam/default/lib/astring -I /home/marc/.opam/default/lib/base -I /home/marc/.op[...]
# File "src/lib_stdlib_unix/file_descriptor_sink.ml", line 116, characters 16-24:
# 116 | Fmt.strf "%s-%d%s" chopped (Unix.getpid ()) ext
# ^^^^^^^^
# Alert deprecated: Fmt.strf
# use Fmt.str instead.
# (cd _build/default && /home/marc/.opam/default/bin/ocamlopt.opt -w -40 -open Tezos_error_monad -open Tezos_error_monad.TzLwtreslib -open Tezos_event_logging -open Tezos_stdlib -open Data_encoding -g -I src/lib_stdlib_unix/.tezos_stdlib_unix.objs/byte -I src/lib_stdlib_unix/.tezos_stdlib_unix.objs/native -I /home/marc/.opam/default/lib/angstrom -I /home/marc/.opam/default/lib/astring -I /home/[...]
# File "src/lib_stdlib_unix/file_descriptor_sink.ml", line 116, characters 16-24:
# 116 | Fmt.strf "%s-%d%s" chopped (Unix.getpid ()) ext
# ^^^^^^^^
# Alert deprecated: Fmt.strf
# use Fmt.str instead.
<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build tezos-stdlib-unix 10.2
└─
╶─ No changes have been performed
How can I resolve this error?

Problem at building conf-pkg-config 2 when installing tsdl with opam on windows 64

I get this error when installing tsdl for my caml project:
#=== ERROR while compiling conf-pkg-config.2 ==================================#
# context 2.0.8 | win32/x86_64 | ocaml-variants.4.11.1+mingw64c | git+https:
//github.com/fdopen/opam-repository-mingw.git#opam2
# path ~/.opam/4.11.1+mingw64c/.opam-switch/build/conf-pkg-config.2
# command dash.exe -ec pkg-config --help
# exit-code 127
# env-file ~/.opam/log/conf-pkg-config-1212-9b8556.env
# output-file ~/.opam/log/conf-pkg-config-1212-9b8556.out
### output ###
# dash: 1: pkg-config: not found
In the error message you have:
# dash: 1: pkg-config: not found
Have you tried
sudo apt install pkg-config

Why is brew not compiling boost correctly?

I'm on Mac OSX Yosemite 10.10.3, and brew install boost is not compiling boost correctly. For example, running
g++ -I/usr/local/Cellar/include -x c++ -E /dev/null -include boost/version.hpp && echo SUCCESS:
gives me
# 1 "/dev/null"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 326 "<built-in>" 3
# 1 "<command line>" 1
In file included from <built-in>:326:
<command line>:1:10: fatal error: 'boost/version.hpp' file not found
#include "boost/version.hpp"
^
# 1 "<built-in>" 2
# 1 "/dev/null" 2
I noticed that the directory structure obtained through Brew installing is substantially different from the one listed here: http://www.boost.org/doc/libs/1_35_0/more/getting_started/unix-variants.html Maybe this doesn't affect anything.
The command should instead be
g++ -I/usr/local/include -x c++ -E /dev/null -include boost/version.hpp && echo SUCCESS

Clang version in Yosemite

I am trying to install MeTA for text retrieval on Mac OS Yosemite (upgraded from Snow Lion).
I am unable to make the project. Apparently, an old version of Clang (3.2) is used.
I updated Xcode and Command line tools, but the new Apple version of clang is not used for making the project.
When installing MeTA I used the following commands:
git clone https://github.com/meta-toolkit/meta.git
cd meta/
git reset --hard v1.3.2
# set up submodules
git submodule update --init --recursive
# set up a build directory
mkdir build
cd build
cp ../config.toml .
# configure and build the project
CXX=clang++ cmake ../ -DCMAKE_BUILD_TYPE=Release -DICU_ROOT=/usr/local/opt/icu4c
make
Clang version
clang -v and it displays:
clang version 3.2 (tags/RELEASE_32/final)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
and after make I get the following error:
[ 0%] Building CXX object src/util/CMakeFiles/meta-util.dir/progress.cpp.o
Assertion failed: (getContainingDC(DC) == CurContext && "The next DeclContext should be lexically contained in the current one."), function PushDeclContext, file SemaDecl.cpp, line 915.
0 libLLVM-3.2svn.dylib 0x0000000105595e52 PrintStackTrace(void*) + 34
1 libLLVM-3.2svn.dylib 0x0000000105596379 SignalHandler(int) + 713
2 libsystem_platform.dylib 0x00007fff9b31df1a _sigtramp + 26
3 libLLVM-3.2svn.dylib 0x0000000105d16cea (anonymous namespace)::StripSymbols::ID + 237935
4 libLLVM-3.2svn.dylib 0x0000000105596096 abort + 22
5 libLLVM-3.2svn.dylib 0x0000000105596055 __assert_rtn + 53
6 clang 0x0000000103ab9c2f clang::Sema::PushDeclContext(clang::Scope*, clang::DeclContext*) + 95
7 clang 0x0000000103c12753 clang::Sema::ActOnStartOfLambdaDefinition(clang::LambdaIntroducer&, clang::Declarator&, clang::Scope*) + 1267
8 clang 0x00000001039dd947 clang::Parser::ParseLambdaExpressionAfterIntroducer(clang::LambdaIntroducer&) + 3207
9 clang 0x00000001039dc757 clang::Parser::ParseLambdaExpression() + 359
10 clang 0x00000001039d0fd5 clang::Parser::ParseCastExpression(bool, bool, bool&, clang::Parser::TypeCastState) + 5797
11 clang 0x00000001039cd127 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) + 135
12 clang 0x00000001039a6a8e clang::Parser::ParseLexedMethodDeclaration(clang::Parser::LateParsedMethodDeclaration&) + 702
13 clang 0x00000001039a6405 clang::Parser::ParseLexedMethodDeclarations(clang::Parser::ParsingClass&) + 165
14 clang 0x00000001039a6405 clang::Parser::ParseLexedMethodDeclarations(clang::Parser::ParsingClass&) + 165
15 clang 0x00000001039c6ae8 clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, unsigned int, clang::Decl*) + 4136
16 clang 0x00000001039c519e clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext) + 6734
17 clang 0x00000001039aedfa clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*) + 1722
18 clang 0x0000000103a0c709 clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) + 73
19 clang 0x0000000103a0c3a7 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) + 359
20 clang 0x0000000103a0b9de clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) + 2558
21 clang 0x00000001039bfac9 clang::Parser::ParseInnerNamespace(std::vector<clang::SourceLocation, std::allocator<clang::SourceLocation> >&, std::vector<clang::IdentifierInfo*, std::allocator<clang::IdentifierInfo*> >&, std::vector<clang::SourceLocation, std::allocator<clang::SourceLocation> >&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) + 521
22 clang 0x00000001039bf092 clang::Parser::ParseNamespace(unsigned int, clang::SourceLocation&, clang::SourceLocation) + 4338
23 clang 0x00000001039ae2b0 clang::Parser::ParseDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, unsigned int, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&) + 416
24 clang 0x0000000103a0b4eb clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) + 1291
25 clang 0x00000001039bfac9 clang::Parser::ParseInnerNamespace(std::vector<clang::SourceLocation, std::allocator<clang::SourceLocation> >&, std::vector<clang::IdentifierInfo*, std::allocator<clang::IdentifierInfo*> >&, std::vector<clang::SourceLocation, std::allocator<clang::SourceLocation> >&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) + 521
26 clang 0x00000001039bf092 clang::Parser::ParseNamespace(unsigned int, clang::SourceLocation&, clang::SourceLocation) + 4338
27 clang 0x00000001039ae2b0 clang::Parser::ParseDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, unsigned int, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&) + 416
28 clang 0x0000000103a0b4eb clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) + 1291
29 clang 0x0000000103a0af57 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) + 311
30 clang 0x00000001039a4d96 clang::ParseAST(clang::Sema&, bool, bool) + 422
31 clang 0x0000000103961b0d clang::CodeGenAction::ExecuteAction() + 173
32 clang 0x00000001037286c9 clang::FrontendAction::Execute() + 105
33 clang 0x000000010370736d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 973
34 clang 0x00000001036cbf2a clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 3322
35 clang 0x00000001036c3b58 cc1_main(char const**, char const**, char const*, void*) + 808
36 clang 0x00000001036c8678 main + 3352
37 libdyld.dylib 0x00007fff9175f5c9 start + 1
Stack dump:
0. Program arguments: /opt/local/libexec/llvm-3.2/bin/clang -cc1 -triple x86_64-apple-macosx10.10.0 -emit-obj -disable-free -main-file-name progress.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 236.3 -coverage-file /Users/gadebski/meta/build/src/util/CMakeFiles/meta-util.dir/progress.cpp.o -resource-dir /opt/local/libexec/llvm-3.2/bin/../lib/clang/3.2 -isystem /usr/local/opt/icu4c/include -D CPPTOML_HAS_STD_PUT_TIME=1 -D CPPTOML_HAS_STD_REGEX=1 -D META_HAS_CXX14=1 -D META_HAS_STD_SHARED_PTR_ATOMICS=1 -D META_HAS_STREAM_MOVE=1 -D META_HAS_ZLIB -D META_IS_DARWIN=1 -D _DARWIN_USE_64_BIT_INODE=1 -D NDEBUG -I /Users/gadebski/meta/include -I /Users/gadebski/meta/deps/cpptoml/include -fmodule-cache-path /var/folders/09/2hnh3rds4wj2swg38_j37k600000gn/T/clang-module-cache -stdlib=libc++ -stdlib=libc++ -O3 -Wall -Wextra -pedantic -std=c++1y -fdeprecated-macro -fdebug-compilation-dir /Users/gadebski/meta/build/src/util -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.10.0 -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o CMakeFiles/meta-util.dir/progress.cpp.o -x c++ /Users/gadebski/meta/src/util/progress.cpp
1. /Users/gadebski/meta/include/logging/logger.h:243:33: current parser token '{'
2. /Users/gadebski/meta/include/logging/logger.h:21:1: parsing namespace 'meta'
3. /Users/gadebski/meta/include/logging/logger.h:27:1: parsing namespace 'logging'
4. /Users/gadebski/meta/include/logging/logger.h:34:1: parsing struct/union/class body 'logger'
5. /Users/gadebski/meta/include/logging/logger.h:243:13: lambda expression parsing
clang: error: unable to execute command: Illegal instruction: 4
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 3.2 (tags/RELEASE_32/final)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
clang: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script.
clang: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /var/folders/09/2hnh3rds4wj2swg38_j37k600000gn/T/progress-grMRZd.cpp
clang: note: diagnostic msg: /var/folders/09/2hnh3rds4wj2swg38_j37k600000gn/T/progress-grMRZd.sh
clang: note: diagnostic msg:
********************
make[2]: *** [src/util/CMakeFiles/meta-util.dir/progress.cpp.o] Error 254
make[1]: *** [src/util/CMakeFiles/meta-util.dir/all] Error 2
make: *** [all] Error 2
I finally solved my problem by manually uninstalling clang 3.2. This made the system recognize the Apple version of clang. Then, I reinstalled cmake. And the MeTA installation went smoothly and all 14 tests passed.

Disable some feauture while building Gstreamer Lib which cause Error?

I'm build gstreamer, at the step of building gstpgood/ext/aalib
The error log is
make[3]: Entering directory `sigma-gstreamer_1-2-rc5/build/gstpgood/ext'
make -C aalib
make[4]: Entering directory `/sigma-gstreamer_1-2-rc5/build/gstpgood/ext/aalib'
CC libgstaasink_la-gstaasink.lo
cc1: error: include location "/usr/include" is unsafe for cross-compilation [-Werror=poison-system-directories]
cc1: all warnings being treated as errors
make[4]: *** [libgstaasink_la-gstaasink.lo] Error 1
My friend build the same source on the other build host did not get this error. I compared gstpgood makefiles and found that my makefile has:
AALIB_CFLAGS = -I/usr/include
AALIB_CONFIG = /usr/bin/aalib-config
AALIB_LIBS = -L/usr/lib/x86_64-linux-gnu -laa
while my friend's make file has
AALIB_CFLAGS =
AALIB_CONFIG = no
AALIB_LIBS =
This aalib is used by aasink, how can i disable aasink when compiling gstreamer???
Pass --disable-aalib to configure before running make. Check ./configure --help for many other things you could disable.
Thank Sebastian Dröge!
I also find a way to bypass aalib check by editing .m4 file in: gstreamer/ext/gstpgood/m4/aalib.m4 it worked for me
#force disable aalibtes by putting enable_aalibtest=no
AC_ARG_ENABLE(aalibtest,
AC_HELP_STRING([--disable-aalibtest],
[do not try to compile and run a test AALIB program]),
, enable_aalibtest=yes)
enable_aalibtest=no
#comment some code
# AC_PATH_PROG(AALIB_CONFIG, aalib-config, no)
# min_aalib_version=ifelse([$1], ,0.11.0,$1)
# AC_MSG_CHECKING(for AALIB - version >= $min_aalib_version)
no_aalib=""
# if test "$AALIB_CONFIG" = "no" ; then
if test x$aalib_prefix == x ; then#add this line
no_aalib=yes
else
AALIB_CFLAGS="-I$aalib_prefix/include"#add this line
AALIB_LIBS="-L$aalib_prefix/lib -laa"#add this line
# AALIB_CFLAGS=`$AALIB_CONFIG $aalibconf_args --cflags`
# AALIB_LIBS=`$AALIB_CONFIG $aalibconf_args --libs`
# aalib_major_version=`$AALIB_CONFIG $aalib_args --version | \
# sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
# aalib_minor_version=`$AALIB_CONFIG $aalib_args --version | \
# sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
# aalib_micro_version=`$AALIB_CONFIG $aalib_config_args --version | \
# sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`