Skip to content
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

Project cannot be built with both recent gcc and clang #21

Closed
tesuji opened this issue Feb 26, 2021 · 3 comments
Closed

Project cannot be built with both recent gcc and clang #21

tesuji opened this issue Feb 26, 2021 · 3 comments

Comments

@tesuji
Copy link

tesuji commented Feb 26, 2021

I cannot build this project with both gcc and clang on latest commit as this time: 6630781.

I'm happy to answer more questions about my build environment if that helps.

Expected Behavior

Build shall pass.

Current Behavior

Build fails.

With clang:

`make -j32`
archive_file.cc:39:17: error: no matching constructor for initialization of 'std::string' (aka 'basic_string<char>')
    std::string name(start, strstr(start, "/\n"));
                ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~
archive_file.cc:70:12: error: no viable overloaded '='
      name = {start, strstr(start, "/\n")};
      ~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

With gcc by changing CC and CXX in makefile.

`make -j32`
subprocess.cc: In function ‘std::function<void()> fork_child()’:
subprocess.cc:33:34: error: taking address of temporary array
   33 |     if (read(pipefd[0], (char[1]){}, 1) == 1)
      |                                  ^~
subprocess.cc: In lambda function:
subprocess.cc:48:44: error: taking address of temporary array
   48 |   return [=]() { write(pipefd[1], (char []){1}, 1); };
      |                                            ^~~
subprocess.cc: In function ‘bool resume_daemon(char**, i64*)’:
subprocess.cc:153:31: error: taking address of temporary array
  153 |   i64 r = read(conn, (char[1]){}, 1);
      |                               ^~
subprocess.cc: In lambda function:
subprocess.cc:218:47: error: taking address of temporary array
  218 |   *on_complete = [=]() { write(conn, (char []){1}, 1); };
      |                                               ^~~
icf.cc:69:19: warning: ‘template<class Key> class tbb::tbb_hash’ is deprecated: tbb::tbb_hash is deprecated, use std::hash [-Wdeprecated-declarations]
   69 | template<> struct tbb_hash<Digest> {
      |                   ^~~~~~~~
In file included from oneTBB/include/tbb/concurrent_hash_map.h:35,
                 from mold.h:21,
                 from icf.cc:53:
oneTBB/include/tbb/internal/_tbb_hash_compare_impl.h:86:74: note: declared here
   86 | class __TBB_DEPRECATED_MSG("tbb::tbb_hash is deprecated, use std::hash") tbb_hash
      |                                                                          ^~~~~~~~
At global scope:
cc1plus: note: unrecognized command-line option ‘-Wno-deprecated-volatile’ may have been intended to silence earlier diagnostics

Context (Environment)

gcc --version: gcc (GCC) 10.2.0
clang version 11.0.0 x86_64-unknown-linux-gnu
OS: Linux 4.19.0-0.bpo.9-amd64 #1 SMP Debian 4.19.118-2+deb10u1~bpo9+1 (2020-06-09) x86_64 GNU/Linux
glibc:
@rui314
Copy link
Owner

rui314 commented Feb 26, 2021

mold is written in C++20. You need a very recent version of clang or gcc as well as libstdc++. I'm using Ubuntu 20 right now, and even though I don't remember what packages I installed, I could set up a build env only with apt-get.

@xyproto
Copy link

xyproto commented Mar 8, 2021

mold builds here on Arch Linux using Clang 11.1.0 (the latest released version), but not GCC 10.2.0 (the latest released version).

I tried by changing CXX and CC at the top of the Makefile to g++ and gcc.

btw, if the top of the makefile was:

CC?=clang
CXX?=clang++

instead of

CC=clang
CXX=clang++

Then CC and CXX would be respected when running CXX=clang++ CC=clang make.

gjimye added a commit to gjimye/mold that referenced this issue May 14, 2021
When using the (begin, end) constructor for string, the types of begin
and end must match, including cv qualifiers. Depending on the library
headers used, strstr(const char *, const char*) can potentially return
char * or const char *, the former being a call to the C function strstr
and the latter being a call to C++ std::strstr.

This commit fixes the clang portion of issue rui314#21, by explicitly casting
the return value of strstr to match the 1st param of the string ctor so
that the ctor can be instantiated regardless of the header used.
gjimye added a commit to gjimye/mold that referenced this issue Jun 4, 2021
When using the (begin, end) constructor for string, the types of begin
and end must match, including cv qualifiers. Depending on the library
headers used, strstr(const char *, const char *) can potentially return
char * or const char *, the former being a call to the C function strstr
and the latter being a call to C++ std::strstr.

This commit fixes the clang portion of issue rui314#21, by explicitly casting
the return value of strstr to match the 1st param of the string ctor so
that the ctor can be instantiated regardless of the header used.

Signed-off-by: Jim Ye <gjimye@gmail.com>
@rui314
Copy link
Owner

rui314 commented Jul 21, 2021

I believe mold can now be built both with clang and with gcc.

@rui314 rui314 closed this as completed Jul 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants