vendredi 5 novembre 2021

clang: error: linker command failed with exit code 1 (use -v to see invocation) when using CMakelist

I created a simple C++ program. I am getting the linked error. The code is below.

main.cxx

#include <iostream>
#include "test.hxx"

int main(void)
{
    testns::testBuff<int, 10> bufferObj;
    bufferObj.reset();
    return 0;
}

test.cxx

#include <array>
#include <unistd.h>
#include "test.hxx"

namespace testns
{

template <class T, size_t TSize>
void testBuff<T, TSize>::reset()
{
    //reset
}
} //namespace testns

test.hxx

namespace ringbuff
{

template <class T, size_t TSize>
class testBuff
{
 public:
    explicit testBuff() = default;
    void   reset();
};
} //namespace testns

CMakeLists

CMAKE_MINIMUM_REQUIRED(VERSION 3.8.2)

SET(CMAKE_CXX_STANDARD 20)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
  
STRING(TOLOWER ${PROJECT_NAME} PROJECT_EXE_NAME)
 
SET(DIR_WORKSPACE ${PROJECT_SOURCE_DIR}/..)
 
SET(DIR_TB ${DIR_WORKSPACE}/TestBuffer)
SET(DIR_TB_INCLUDE ${DIR_TB}/include)
SET(DIR_TB_SRC ${DIR_TB}/src)
 
file (GLOB_RECURSE ALL_TB_CPP_FILES ${DIR_TB_SRC}/*.cxx)

SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> crP <TARGET> <OBJECTS>")
SET(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> rP <TARGET> <OBJECTS>")
 
ADD_EXECUTABLE(${PROJECT_EXE_NAME}
               ${ALL_TB_CPP_FILES}
               )
               
TARGET_INCLUDE_DIRECTORIES(
    ${PROJECT_EXE_NAME} PUBLIC
    ${DIR_TB_INCLUDE}
    ${CMAKE_BINARY_DIR}/include
    ${CMAKE_INSTALL_PREFIX}/include
)
 
TARGET_COMPILE_OPTIONS(
    ${PROJECT_EXE_NAME}
  PRIVATE
    -fvisibility=hidden
    -pipe
    -Wall
    -Werror
    -Wextra
    -Wfloat-conversion
    -Wformat
    -Wformat-security
    -Werror=format-security
)
 
TARGET_LINK_LIBRARIES(
    ${PROJECT_EXE_NAME}
    ${log-lib}
    )
    

Error: Linker Error clang: error: linker command failed with exit code 1 (use -v to see invocation) make[2]: *** [CMakeFiles/project.dir/build.make:114: project] Error 1 make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/project.dir/all] Error 2 make: *** [Makefile:84: all] Error 2

I am using the clang compiler. Can someone help me what I am missing and why there is a linker error?

Thank you

Aucun commentaire:

Enregistrer un commentaire