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

Doesn't build with Clang on Linux #18

Closed
mrzv opened this issue Nov 29, 2015 · 3 comments
Closed

Doesn't build with Clang on Linux #18

mrzv opened this issue Nov 29, 2015 · 3 comments

Comments

@mrzv
Copy link

mrzv commented Nov 29, 2015

-flto option prevents the example code from building on Linux with Clang (3.7). The problem is with the linker, it simply complains:

CMakeFiles/example.dir/example/example.cpp.o: file not recognized: File format not recognized

Removing -flto fixes everything. Apparently, this is not an unusual issue with Clang.

@wjakob
Copy link
Member

wjakob commented Nov 30, 2015

Hi,

you need to use the 'gold' linker (http://llvm.org/docs/GoldPlugin.html) to use link time optimization with Clang. Maybe you are using plain LD? I prefer to have -flto in the build file by default as it leads to considerably smaller binaries. However, maybe support can be detected?

I can't reproduce this here right now, so I am wondering if something like the following works for the CMakeLists.txt file? (in line 36)

  if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
    CHECK_CXX_COMPILER_FLAG("-flto" HAS_LTO_FLAG)
    if (HAS_LTO_FLAG)
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -flto")
    endif() 
  endif()

Thanks,
Wenzel

@wjakob
Copy link
Member

wjakob commented Nov 30, 2015

Actually, this would be even better:

  # Enable link time optimization and set the default symbol
  # visibility to hidden (very important to obtain small binaries)
  if (HAS_LTO_FLAG AND NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
    # Default symbol visibility
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")

    # Check for Link Time Optimization support
    CHECK_CXX_COMPILER_FLAG("-flto" HAS_LTO_FLAG)
    if (HAS_LTO_FLAG)
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
    endif()
  endif()

Does that work for you?

@mrzv
Copy link
Author

mrzv commented Nov 30, 2015

Yup, this works. Thanks.

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

2 participants