0

this is my directory

  • ---untitled
  • --------main.cpp
  • --------ttalloc.h
  • --------ttalloc.cpp

And this is my CMakeLists.txt

cmake_minimum_required(VERSION 3.12)
project(untitled)

set(CMAKE_CXX_STANDARD 14)
set(SRC ttalloc.cpp)

add_library(alloc ttalloc.cpp)
add_executable(untitled main.cpp)

target_link_libraries(untitled alloc)
target_include_directories(untitled PUBLIC ${PROJECT_SOURCE_DIR})

This is the "main" funtion:

int main()
{
    TT::allocator<int> allocator;
    TT::allocator<int>::pointer p = allocator.allocate(5);
    for(int i=0;i<5;i++)
        allocator.construct(p+i,i);

    for(int i=0;i<5;i++)
        std::cout << *(p+i) << " ";

    allocator.deallocate(p,5);
}

When i build my main.cpp, I got the error:

  • undefined reference to `TT::allocator::allocate(unsigned long long, void const*)'
  • undefined reference to `TT::allocator::construct(int*, int const&)'
  • undefined reference to `TT::allocator::deallocate(int*, unsigned long long)'
jptang
  • 1
  • 2

0 Answers0