What are the compiler/linker requirements for using pthread library with clang in OS X.
With GCC i know that using -pthread set the appropriate compiler/linker options, but i unsure about OS X with clang.
air:~ jose$ clang++ -c test.cpp -pthread
air:~ jose$ clang++ -o test -pthread test.o
clang: warning: argument unused during compilation: '-pthread'
air:~ jose$ g++ -c test.cpp -pthread
air:~ jose$ g++ -o test -pthread test.o
clang requires -pthread when compiling but not when linking. This is annoying, but it is observed behavior:
$ clang -c x.cpp
$ clang -pthread -c x.cpp
$ clang -o x x.o
$ clang -pthread -o x x.o
clang: warning: argument unused during compilation: '-pthread'
$
$ clang --version
Apple LLVM version 5.0 (clang-500.2.76) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
$
Related
I have a std::tuple< std::optional<Args> ... >, need to check that every element has a value.
I have implemented it with std::index_sequence. But I'm not sure this is the most efficient solution for fastest compile time.
using data_type = std::tuple< std::optional<Arg_1>,
std::optional<Arg_2>,
//....
std::optional<Arg_n> // where n > 40
>;
// My solution.
template <size_t ... indexes>
bool has_value_all_elements_impl(const data_type& tuple_data, std::index_sequence<indexes ...> ) {
//I assume there O(n) lookup for each index in compile time.
// So total O(n^2) lookup for tuple ?
return (std::get<indexes>(tuple_data).has_value() && ... ) ;
}
bool has_value_all_elements(data_type const& tuple_data)
{
return has_value_all_elements_impl(
tuple_data, std::make_index_sequence<std::tuple_size<data_type>::value>{});
}
Is there a more efficient O(n) algorithm for such problem?
Or is my solution already O(n) ?
I decided answer my own question.
Seems #chronial comment is right.
source code on godbold - Seems, it depends STL implementation. GCC stdlibc++ increased compile time is not linear. libc++ increased compile time is linear.
GCC:
$ g++ --version
g++ (Ubuntu 11.1.0-1ubuntu1~20.04) 11.1.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ time g++ -DARG_SIZE=10 -Wall -o "example" "example.cpp" -std=c++17 -lpthread -Wall -Wextra -pedantic -O2
real 0m0.431s
user 0m0.384s
sys 0m0.047s
$ time g++ -DARG_SIZE=20 -Wall -o "example" "example.cpp" -std=c++17 -lpthread -Wall -Wextra -pedantic -O2
real 0m0.507s
user 0m0.461s
sys 0m0.046s
$ time g++ -DARG_SIZE=40 -Wall -o "example" "example.cpp" -std=c++17 -lpthread -Wall -Wextra -pedantic -O2
real 0m0.737s
user 0m0.666s
sys 0m0.071s
$ time g++ -DARG_SIZE=80 -Wall -o "example" "example.cpp" -std=c++17 -lpthread -Wall -Wextra -pedantic -O2
real 0m2.030s
user 0m1.882s
sys 0m0.148s
$ time g++ -DARG_SIZE=160 -Wall -o "example" "example.cpp" -std=c++17 -lpthread -Wall -Wextra -pedantic -O2
real 0m23.532s
user 0m23.216s
sys 0m0.312s
$ time g++ -DARG_SIZE=320 -Wall -o "example" "example.cpp" -std=c++17 -lpthread -Wall -Wextra -pedantic -O2
real 10m40.392s
user 10m37.992s
sys 0m2.067s
CLang:
$ clang++ --version
Ubuntu clang version 12.0.0-3ubuntu1~20.04.5
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ time clang++ -DARG_SIZE=10 -Wall -o "example" "example.cpp" -std=c++17 -stdlib=libc++ -lpthread -Wall -Wextra -pedantic -O2
example.cpp:36:15: warning: unused variable 'd' [-Wunused-variable]
data_type d;
^
1 warning generated.
real 0m1.056s
user 0m0.667s
sys 0m0.066s
$ time clang++ -DARG_SIZE=20 -Wall -o "example" "example.cpp" -std=c++17 -stdlib=libc++ -lpthread -Wall -Wextra -pedantic -O2
example.cpp:36:15: warning: unused variable 'd' [-Wunused-variable]
data_type d;
^
1 warning generated.
real 0m0.816s
user 0m0.764s
sys 0m0.048s
$ time clang++ -DARG_SIZE=40 -Wall -o "example" "example.cpp" -std=c++17 -stdlib=libc++ -lpthread -Wall -Wextra -pedantic -O2
example.cpp:36:15: warning: unused variable 'd' [-Wunused-variable]
data_type d;
^
1 warning generated.
real 0m1.455s
user 0m0.985s
sys 0m0.095s
$ time clang++ -DARG_SIZE=80 -Wall -o "example" "example.cpp" -std=c++17 -stdlib=libc++ -lpthread -Wall -Wextra -pedantic -O2
example.cpp:36:15: warning: unused variable 'd' [-Wunused-variable]
data_type d;
^
1 warning generated.
real 0m1.565s
user 0m1.484s
sys 0m0.067s
$ time clang++ -DARG_SIZE=160 -Wall -o "example" "example.cpp" -std=c++17 -stdlib=libc++ -lpthread -Wall -Wextra -pedantic -O2
example.cpp:36:15: warning: unused variable 'd' [-Wunused-variable]
data_type d;
^
1 warning generated.
real 0m3.172s
user 0m2.410s
sys 0m0.080s
$ time clang++ -DARG_SIZE=320 -Wall -o "example" "example.cpp" -std=c++17 -stdlib=libc++ -lpthread -Wall -Wextra -pedantic -O2 -fbracket-depth=400
example.cpp:36:15: warning: unused variable 'd' [-Wunused-variable]
data_type d;
^
1 warning generated.
real 0m4.576s
user 0m4.337s
sys 0m0.238s
I downloaded zlib from https://zlib.net/ and execute ./configure and make cmd. However, it shows that there are some undefined symbols for architecture arm64. How to build zlib in this case?
I'm using a macbookpro 2021 with apple m1pro chip.
The full info is:
~/GitClone/zlib-1.2.11 > ./configure at 15:42:53
Checking for gcc...
Checking for shared library support...
Building shared library libz.1.2.11.dylib with gcc.
Checking for size_t... Yes.
Checking for off64_t... No.
Checking for fseeko... Yes.
Checking for strerror... Yes.
Checking for unistd.h... Yes.
Checking for stdarg.h... Yes.
Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf().
Checking for vsnprintf() in stdio.h... Yes.
Checking for return value of vsnprintf()... Yes.
Checking for attribute(visibility) support... Yes.
~/GitClone/zlib-1.2.11 > make at 15:43:13
gcc -O3 -DHAVE_HIDDEN -I. -c -o example.o test/example.c
gcc -O3 -DHAVE_HIDDEN -c -o adler32.o adler32.c
gcc -O3 -DHAVE_HIDDEN -c -o crc32.o crc32.c
gcc -O3 -DHAVE_HIDDEN -c -o deflate.o deflate.c
gcc -O3 -DHAVE_HIDDEN -c -o infback.o infback.c
gcc -O3 -DHAVE_HIDDEN -c -o inffast.o inffast.c
gcc -O3 -DHAVE_HIDDEN -c -o inflate.o inflate.c
gcc -O3 -DHAVE_HIDDEN -c -o inftrees.o inftrees.c
gcc -O3 -DHAVE_HIDDEN -c -o trees.o trees.c
gcc -O3 -DHAVE_HIDDEN -c -o zutil.o zutil.c
gcc -O3 -DHAVE_HIDDEN -c -o compress.o compress.c
gcc -O3 -DHAVE_HIDDEN -c -o uncompr.o uncompr.c
gcc -O3 -DHAVE_HIDDEN -c -o gzclose.o gzclose.c
gcc -O3 -DHAVE_HIDDEN -c -o gzlib.o gzlib.c
gcc -O3 -DHAVE_HIDDEN -c -o gzread.o gzread.c
gcc -O3 -DHAVE_HIDDEN -c -o gzwrite.o gzwrite.c
libtool -o libz.a adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o
gcc -O3 -DHAVE_HIDDEN -o example example.o -L. libz.a
ld: warning: ignoring file libz.a, building for macOS-arm64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture arm64:
"_compress", referenced from:
_test_compress in example.o
(maybe you meant: _test_compress)
"_deflate", referenced from:
_test_deflate in example.o
_test_large_deflate in example.o
_test_flush in example.o
_test_dict_deflate in example.o
(maybe you meant: _test_large_deflate, _test_deflate , _test_dict_deflate )
"_deflateEnd", referenced from:
_test_deflate in example.o
_test_large_deflate in example.o
_test_flush in example.o
_test_dict_deflate in example.o
"_deflateInit_", referenced from:
_test_deflate in example.o
_test_large_deflate in example.o
_test_flush in example.o
_test_dict_deflate in example.o
"_deflateParams", referenced from:
_test_large_deflate in example.o
"_deflateSetDictionary", referenced from:
_test_dict_deflate in example.o
"_gzclose", referenced from:
_test_gzio in example.o
"_gzerror", referenced from:
_test_gzio in example.o
"_gzgetc", referenced from:
_test_gzio in example.o
"_gzgets", referenced from:
_test_gzio in example.o
"_gzopen", referenced from:
_test_gzio in example.o
"_gzprintf", referenced from:
_test_gzio in example.o
"_gzputc", referenced from:
_test_gzio in example.o
"_gzputs", referenced from:
_test_gzio in example.o
"_gzread", referenced from:
_test_gzio in example.o
"_gzseek", referenced from:
_test_gzio in example.o
"_gztell", referenced from:
_test_gzio in example.o
"_gzungetc", referenced from:
_test_gzio in example.o
"_inflate", referenced from:
_test_inflate in example.o
_test_large_inflate in example.o
_test_sync in example.o
_test_dict_inflate in example.o
(maybe you meant: _test_large_inflate, _test_inflate , _test_dict_inflate )
"_inflateEnd", referenced from:
_test_inflate in example.o
_test_large_inflate in example.o
_test_sync in example.o
_test_dict_inflate in example.o
"_inflateInit_", referenced from:
_test_inflate in example.o
_test_large_inflate in example.o
_test_sync in example.o
_test_dict_inflate in example.o
"_inflateSetDictionary", referenced from:
_test_dict_inflate in example.o
"_inflateSync", referenced from:
_test_sync in example.o
"_uncompress", referenced from:
_test_compress in example.o
"_zlibCompileFlags", referenced from:
_main in example.o
"_zlibVersion", referenced from:
_main in example.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [example] Error 1
The clang version and environment variable is like:
~ > clang --version at 16:22:31
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
~ > clang++ --version at 16:22:34
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
~ > echo $PATH at 16:22:37
/usr/local/include:/opt/homebrew/Cellar/binutils/2.38_1/bin:/Users/hanxiaohao/.npm-global/bin:/Library/Java/JavaVirtualMachines/jdk-18.0.2.jdk/Contents/Home/bin:/opt/homebrew/Cellar/binutils/2.38_1/bin:/Users/hanxiaohao/.npm-global/bin:/Library/Java/JavaVirtualMachines/jdk-18.0.2.jdk/Contents/Home/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/hanxiaohao/Library/Application Support/JetBrains/Toolbox/scripts:/opt/homebrew/Cellar/maven/3.6.3/bin:/opt/homebrew/Cellar/maven/3.6.3/bin
Not reproducible.
Tested on M1 Max macOS 12.5.1 with XCode 13.4.1 and Homebrew in the /opt/homebrew directory.
I noticed you have /usr/local/include and /usr/local/bin in your path. Those should be non-existent on M1 macOS. They were for Homebrew Intel.
% ls -l /usr/local/include /usr/local/bin
ls: /usr/local/bin: No such file or directory
ls: /usr/local/include: No such file or directory
Here is the run log of my test:
% ./configure
Checking for gcc...
Checking for shared library support...
Building shared library libz.1.2.12.dylib with gcc.
Checking for size_t... Yes.
Checking for off64_t... No.
Checking for fseeko... Yes.
Checking for strerror... Yes.
Checking for unistd.h... Yes.
Checking for stdarg.h... Yes.
Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf().
Checking for vsnprintf() in stdio.h... Yes.
Checking for return value of vsnprintf()... Yes.
Checking for attribute(visibility) support... Yes.
% make
gcc -O3 -DHAVE_HIDDEN -I. -c -o example.o test/example.c
gcc -O3 -DHAVE_HIDDEN -c -o adler32.o adler32.c
gcc -O3 -DHAVE_HIDDEN -c -o crc32.o crc32.c
gcc -O3 -DHAVE_HIDDEN -c -o deflate.o deflate.c
gcc -O3 -DHAVE_HIDDEN -c -o infback.o infback.c
gcc -O3 -DHAVE_HIDDEN -c -o inffast.o inffast.c
gcc -O3 -DHAVE_HIDDEN -c -o inflate.o inflate.c
gcc -O3 -DHAVE_HIDDEN -c -o inftrees.o inftrees.c
gcc -O3 -DHAVE_HIDDEN -c -o trees.o trees.c
gcc -O3 -DHAVE_HIDDEN -c -o zutil.o zutil.c
gcc -O3 -DHAVE_HIDDEN -c -o compress.o compress.c
gcc -O3 -DHAVE_HIDDEN -c -o uncompr.o uncompr.c
gcc -O3 -DHAVE_HIDDEN -c -o gzclose.o gzclose.c
gcc -O3 -DHAVE_HIDDEN -c -o gzlib.o gzlib.c
gcc -O3 -DHAVE_HIDDEN -c -o gzread.o gzread.c
gcc -O3 -DHAVE_HIDDEN -c -o gzwrite.o gzwrite.c
libtool -o libz.a adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o
gcc -O3 -DHAVE_HIDDEN -o example example.o -L. libz.a
gcc -O3 -DHAVE_HIDDEN -I. -c -o minigzip.o test/minigzip.c
gcc -O3 -DHAVE_HIDDEN -o minigzip minigzip.o -L. libz.a
gcc -O3 -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/adler32.o adler32.c
gcc -O3 -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/crc32.o crc32.c
gcc -O3 -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/deflate.o deflate.c
gcc -O3 -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/infback.o infback.c
gcc -O3 -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/inffast.o inffast.c
gcc -O3 -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/inflate.o inflate.c
gcc -O3 -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/inftrees.o inftrees.c
gcc -O3 -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/trees.o trees.c
gcc -O3 -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/zutil.o zutil.c
gcc -O3 -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/compress.o compress.c
gcc -O3 -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/uncompr.o uncompr.c
gcc -O3 -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/gzclose.o gzclose.c
gcc -O3 -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/gzlib.o gzlib.c
gcc -O3 -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/gzread.o gzread.c
gcc -O3 -fPIC -DHAVE_HIDDEN -DPIC -c -o objs/gzwrite.o gzwrite.c
gcc -dynamiclib -install_name /usr/local/lib/libz.1.dylib -compatibility_version 1 -current_version 1.2.12 -O3 -fPIC -DHAVE_HIDDEN -o libz.1.2.12.dylib adler32.lo crc32.lo deflate.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo zutil.lo compress.lo uncompr.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo -lc
rm -f libz.dylib libz.1.dylib
ln -s libz.1.2.12.dylib libz.dylib
ln -s libz.1.2.12.dylib libz.1.dylib
gcc -O3 -DHAVE_HIDDEN -o examplesh example.o -L. libz.1.2.12.dylib
gcc -O3 -DHAVE_HIDDEN -o minigzipsh minigzip.o -L. libz.1.2.12.dylib
% gcc --version
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
% clang --version
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
% clang++ --version
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
% uname -a
Darwin Superbook.local 21.6.0 Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:23 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T6000 arm64
I am currently trying to compile a small program I have been working on with Clang and am getting the following error on compilation using scons as the build system:
/usr/bin/clang++ -o src/PluGen/main.o -c -std=c++17 -fPIC -I. -O2 -fno-strict-aliasing -fpermissive -fopenmp --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -fpermissive -fPIC -I. -O2 -flto -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -DHAVE_PYTHON -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DLARGE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_PERL -DREENTRANT -DHAVE_R -I/usr/include -I/usr/local/include -Isrc -I/usr/include/python3.10 -I/usr/lib/perl5/5.36/core_perl/CORE -I/usr/include/R -I/usr/lib/R/library/Rcpp/include -I/usr/lib/R/library/RInside/include -I/usr/lib/R/site-library/RInside/include -I/usr/lib/R/site-library/Rcpp/include -I/usr/local/lib/R/library/Rcpp/include -I/usr/local/lib/R/library/RInside/include -I/usr/local/lib/R/site-library/RInside/include -I/usr/local/lib/R/site-library/Rcpp/include -I/usr/local/lib/R/site-library/RInside/lib src/PluGen/main.cxx
...
/usr/bin/clang++ -o PluGen/plugen -rdynamic -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.36/core_perl/CORE -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now src/PluGen/main.o src/PluGen/PluginGenerator.o -L/lib -L/usr/lib -L/usr/local/lib -L/usr/lib/perl5/5.36/core_perl/CORE -L/usr/lib/R/lib -L/usr/lib/R/library/RInside/lib -L/usr/lib/R/site-library/RInside/lib -L/usr/local/lib/R/library/RInside/lib -L/usr/local/lib/R/site-library/RInside/lib -Llib -lc -lc++ -lstdc++fs
src/PluGen/main.o: file not recognized: file format not recognized
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
main.o is being generated as a IR bitcode
file src/PluGen/main.o
src/PluGen/main.o: LLVM IR bitcode
Running the linker outside of the scons builder yields the following message:
clang version 14.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/12.1.0
Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0
Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0
Candidate multilib: .;#m64
Candidate multilib: 32;#m32
Selected multilib: .;#m64
"/usr/bin/ld" -pie -export-dynamic --eh-frame-hdr -m elf_x86_64 -export-dynamic -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o PluGen/plugen /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../lib64/Scrt1.o /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../lib64/crti.o /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0/crtbeginS.o -L/lib -L/usr/lib -L/usr/local/lib -L/usr/lib/perl5/5.36/core_perl/CORE -L/usr/lib/R/lib -L/usr/lib/R/library/RInside/lib -L/usr/lib/R/site-library/RInside/lib -L/usr/local/lib/R/library/RInside/lib -L/usr/local/lib/R/site-library/RInside/lib -Llib -L/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0 -L/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/bin/../lib -L/lib -L/usr/lib -E -rpath /usr/lib/perl5/5.36/core_perl/CORE -O1 --sort-common --as-needed -z relro -z now src/PluGen/main.o src/PluGen/PluginGenerator.o -lc -lc++ -lstdc++fs -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0/crtendS.o /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../lib64/crtn.o
src/PluGen/main.o: file not recognized: file format not recognized
The program does compile correctly using GCC. Just not with Clang.
What is going on?
You are using -flto when compiling, but not when linking. clang can't do that. -c -flto compiles to LLVM IR bitcodes which the linker cannot use directly. You should either drop -flto everywhere, or use it everywhere.
$ clang++ -flto -c hello.cpp
$ file hello.o
hello.o: LLVM IR bitcode
$ clang++ -o hello hello.o && echo Ok
hello.o: file not recognized: file format not recognized
clang: error: linker command failed with exit code 1 (use -v to see invocation)
$ clang++ -o hello hello.o -flto && echo Ok
Ok
gcc works differently. It compiles to "fat objects" with both machine code and internal compiler representation baked in. Linker can use these, and apply the LTO plugin automatically.
$ g++ -c hello.cpp -flto
$ file hello.o
hello.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
$ g++ -o hello hello.o && echo Ok
Ok
my gcc version is the following:
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
while clang
clang version 10.0.0-4ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
but the following code doesn't compile:
#include <thread>
#include <vector>
int main(){
std::vector<std::jthread> myJThreads;
return 0;
}
I've tried these so far:
g++ -O2 -std=c++2a -Wall -Wextra -Wpedantic -lm -lstdc++ example.cpp -pthread -o example
clang -O2 -std=c++2a -Wall -Wextra -Wpedantic -lm -lstdc++ example.cpp -pthread -o example
clang++-12 -O2 -std=c++2a -Wall -Wextra -Wpedantic -lm -lstdc++ example.cpp -pthread -o example
getting:
error: ‘jthread’ is not a member of ‘std’;
error: no member named 'jthread' in namespace 'std'
how can I fix this?
I can build c++ projects without c++ modules with build2, but when i try to configure and use build2 with c++ modules, I have "compiler does not support modules" error.
I'm sure my compiler is capable of building modules, because I can manually build using these commands:
clang++ --std=c++17 -fmodules-ts --precompile foo.cppm -o foo.pcm
clang++ --std=c++17 -fmodules-ts --precompile foo2.cppm -o foo2.pcm
clang++ --std=c++17 -fmodules-ts -c foo.pcm -o foo.o
clang++ --std=c++17 -fmodules-ts -c foo2.pcm -o foo2.o
clang++ --std=c++17 -fmodules-ts -fprebuilt-module-path=. foo.o foo2.o bar.cpp
Version of my clang is 7.0.0:
$ clang++ --version
clang version 7.0.0- (trunk)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
To enable modules support in build2 I added following lines to root buildfile:
cxx.std = experimental
using cxx
assert $cxx.features.modules 'compiler does not support modules'
mxx{*}: extension = mxx
cxx{*}: extension = cxx
What can be wrong? It's my first time with build2, so I can be missing something very simple.
Managed it to work.
As I understand the problem was that I changed buildfile, but should use build/root.build instead.