9

My per project started having problems with linking to llvm. Whenever I try to run anything linking to llvm, I get the following error:

: CommandLine Error: Option 'help-list' registered more than once!
LLVM ERROR: inconsistency in registered CommandLine options

It seems I am linking maybe twice? But I unclear of how I could be linking it twice.

CMakeLists:

cmake_minimum_required(VERSION 3.10)
project(schwifty)

set(CMAKE_CXX_STANDARD 14)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DELPP_FEATURE_CRASH_LOG")

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out)

find_package(PythonInterp 3.6 REQUIRED)

file(MAKE_DIRECTORY downloads external)

#
# Easylogging++
#
if (EXISTS "external/easyloggingpp")
else ()
    file(MAKE_DIRECTORY external/easyloggingpp)
    file(DOWNLOAD https://github.com/muflihun/easyloggingpp/archive/v9.96.4.zip
            downloads/easyloggingpp.zip)
    execute_process(COMMAND unzip downloads/easyloggingpp.zip -d downloads)
    file(GLOB easyloggingpp_files
            downloads/easyloggingpp-9.96.4/src/easylogging++.*)
    file(COPY ${easyloggingpp_files} DESTINATION external/easyloggingpp)
endif ()

include_directories(external/easyloggingpp)
add_library(easyloggingpp external/easyloggingpp/easylogging++.cc)

#
# Local lib targets
#

add_library(ast ast.h ast.cc)

add_library(ast_compare_visitor ast_compare_visitor.h ast_compare_visitor.cc)

add_library(classes classes.h classes.cc)

add_library(codegen
        codegen.h
        codegen.cc
        codegen_common.h
        codegen_common.cc
        expression_type_visitor.cc
        expression_type_visitor.h)

add_library(common common.h utils.h utils.cc)

add_library(compilation_context
        compilation_context.h
        compilation_context.cc
        enum.h
        enum.cc
        errors.h
        errors.cc
        operators.h
        operators.cc
        type.h
        type.cc)

target_link_libraries(compilation_context common)

add_library(functions functions.h functions.cc)

add_library(jit jit.cc jit.h)

add_library(lexer lexer.cc lexer.h lexer_common.cc lexer_common.h)

add_library(parser parser.h parser.cc)

add_library(runtime runtime.cc runtime.h)

add_library(type_inference
        type_inference.h
        type_inference.cc
        symbol_visitor.cc
        symbol_visitor.h
        type_inference_visitor.cc
        type_inference_visitor.h)

target_link_libraries(type_inference classes compilation_context)

#
# External lib targets
#

find_package(FMT REQUIRED CONFIG)

find_package(LLVM REQUIRED CONFIG)

message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

include_directories(${LLVM_INCLUDE_DIRS})

llvm_map_components_to_libnames(llvm_libs all)

target_link_libraries(codegen ${llvm_libs})

#
# Schwifty main executable
#

add_executable(schwifty schwifty.cc)
target_link_libraries(schwifty
        ast
        classes
        codegen
        common
        compilation_context
        easyloggingpp
        fmt::fmt
        functions
        lexer
        parser
        runtime
        type_inference)

#
# Testing
#

enable_testing()
find_package(GTest REQUIRED)

find_package(Threads)

include_directories(${GTEST_INCLUDE_DIRS})

add_executable(codegen_test codegen_test.cc)
target_link_libraries(codegen_test
        ${GTEST_BOTH_LIBRARIES}
        easyloggingpp
        ast
        classes
        codegen
        common
        compilation_context
        fmt::fmt
        functions
        jit
        lexer
        parser
        runtime
        type_inference
        ${CMAKE_THREAD_LIBS_INIT})
add_test(codegen_test COMMAND out/codegen_test)

add_executable(lexer_test lexer_test.cc)
target_link_libraries(lexer_test
        ${GTEST_BOTH_LIBRARIES}
        ast
        common
        compilation_context
        easyloggingpp
        functions
        lexer
        parser
        fmt::fmt
        ${CMAKE_THREAD_LIBS_INIT})
add_test(lexer_test COMMAND out/lexer_test)

add_executable(parser_test parser_test.cc)
target_link_libraries(parser_test
        ${GTEST_BOTH_LIBRARIES}
        ast
        ast_compare_visitor
        compilation_context
        common
        easyloggingpp
        functions
        lexer
        parser
        fmt::fmt
        ${CMAKE_THREAD_LIBS_INIT})
add_test(parser_test COMMAND out/parser_test)

add_executable(type_test type_test.cc)
target_link_libraries(type_test
        ${GTEST_BOTH_LIBRARIES}
        ast
        compilation_context
        common
        easyloggingpp
        functions
        lexer
        parser
        ${CMAKE_THREAD_LIBS_INIT})
add_test(type_test COMMAND out/type_test)

add_executable(type_inference_test type_inference_test.cc)
target_link_libraries(type_inference_test
        ${GTEST_BOTH_LIBRARIES}
        easyloggingpp
        ast
        classes
        common
        compilation_context
        functions
        fmt::fmt
        lexer
        parser
        runtime
        type_inference
        ${CMAKE_THREAD_LIBS_INIT})
add_test(type_inference_test COMMAND ./out/type_inference_test)

add_test(NAME end_to_end_tests
        WORKING_DIRECTORY ${CTEST_SOURCE_DIRECTORY}
        COMMAND ${PYTHON_EXECUTABLE} end_to_end_tests.py)

Full code: https://bitbucket.org/gruszczy/schwifty/src/default/CMakeLists.txt

7
  • 3
    Seems like you have more than one LLVM version installed on your machine and linker links against libraries from different versions. I suggest trying to link against LLVM library explicitly: target_link_libraries(codegen LLVM) Commented Jan 22, 2019 at 10:29
  • 1
    Thanks a lot for the response, @Alex Denisov! It was indeed that and I was able to fix this by uninstalling one of them. If I would like to have more than one version installed, how is target_link_libraries(codegen LLVM) different from what I have target_link_libraries(codegen ${llvm_libs})?
    – gruszczy
    Commented Jan 24, 2019 at 4:55
  • 2
    the hypothesis is the following: when you link against llvm_libs you get there, let's say, LLVMCore, which somehow depends on libLLVM.dylib, which then is resolved to the other version, instead of the one you want. But please don't quote me on that, this is just a hypothesis :) Commented Jan 24, 2019 at 17:04
  • Thanks a lot for the response, good to have at least some hypothesis!
    – gruszczy
    Commented Jan 25, 2019 at 4:33
  • 2
    Odd, I have the same issue and as far as I know I only have LLVM 9 installed :/
    – Salem
    Commented Jan 18, 2020 at 16:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.