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

Undefined symbols FlagRegister - cmake - fail to link gflags - Boost conflict #291

Open
tgy opened this issue Oct 7, 2019 · 2 comments

Comments

@tgy
Copy link

commented Oct 7, 2019

I have a problem in one of my projects where the program fails to compile because a linking error is raised on some gflags templated functions:

[100%] Linking CXX executable reproduce-issue
Undefined symbols for architecture x86_64:
  "google::FlagRegisterer::FlagRegisterer<bool>(char const*, char const*, char const*, b
ool*, bool*)", referenced from:
      ___cxx_global_var_init.3 in reproduce.cpp.o
  "google::FlagRegisterer::FlagRegisterer<int>(char const*, char const*, char const*, in
t*, int*)", referenced from:
      ___cxx_global_var_init in reproduce.cpp.o
ld: symbol(s) not found for architecture x86_64
clang-8: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [reproduce-issue] Error 1
make[2]: *** [CMakeFiles/reproduce-issue.dir/all] Error 2
make[1]: *** [CMakeFiles/reproduce-issue.dir/rule] Error 2
make: *** [reproduce-issue] Error 2

I have managed to reproduce this issue with a small example. Here are the CMakeLists.txt and reproduce.cpp files:

cmake_minimum_required(VERSION 3.6 FATAL_ERROR)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z -Wall -W -pedantic -g")
set(CMAKE_CXX_FLAGS_DEBUG
    "${CMAKE_CXX_FLAGS} -std=c++1z -Wall -W -pedantic -g")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED on)

project(reproduce LANGUAGES CXX)

add_subdirectory(gflags)

find_package(Boost 1.62.0 REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})

add_executable(
  reproduce-issue
  reproduce.cpp
)
target_link_libraries(reproduce-issue gflags)
#include <gflags/gflags.h>

DEFINE_int32(j, -1, "nb of jobs");
DEFINE_bool(skip, false, "whether to skip already done computations");

int main(void)
{
  return 0;
}

Note that the last version of gflags is cloned next to these two files.

Note also that if I move the add_subdirectory(gflags) instruction after include_directories(${Boost_INCLUDE_DIRS}) everything works fine.

@schuhschuh

This comment has been minimized.

Copy link
Member

commented Oct 8, 2019

A few more details about which OS, compiler + version, and Boost library you are using may be needed. I tried your reproduce example on macOS 10.14.6 with clang 11.0.0 and Boost 1.70 (installed with Homebrew) and it compiled without any error.

@tgy

This comment has been minimized.

Copy link
Author

commented Oct 9, 2019

$ $CXX --version
clang version 8.0.1 (tags/RELEASE_801/final)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /usr/local/Cellar/llvm/8.0.1/bin
$ grep BOOST_LIB_VERSION `locate 'boost/version.hpp'`
//  BOOST_LIB_VERSION must be defined to be the same as BOOST_VERSION
#define BOOST_LIB_VERSION "1_70"
viovene@223-239 ~/p/phd/mdnotes (master)
$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.14.6
BuildVersion:   18G87
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.