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 reference to library function #185

Closed
roelofd opened this issue May 25, 2020 · 1 comment
Closed

Undefined reference to library function #185

roelofd opened this issue May 25, 2020 · 1 comment

Comments

@roelofd
Copy link

roelofd commented May 25, 2020

So I have created a very basic "hello world" kind of project which uses the LLA library. I exactly followed all the build and install tutorials, and now started with the C++ how to. For some reason while trying to compile it gives an "undefined reference" error when a library function is called even though the function does exist in that location. I can't seem to find any useful information. Seems to be a linker issue but how do I fix this?

main.cpp

#include <iostream>

#include <logicalaccess/dynlibrary/librarymanager.hpp>
#include <logicalaccess/readerproviders/readerconfiguration.hpp>
#include <logicalaccess/cards/chip.hpp>

int main()
{
    std::cout << "Program started\n";
    
    // Reader configuration object to store reader provider and reader unit selection.
    std::shared_ptr<logicalaccess::ReaderConfiguration> readerConfig(new logicalaccess::ReaderConfiguration());
           
    // Set PCSC ReaderProvider by calling the Library Manager which will load the function from the    corresponding plug-in
    readerConfig->setReaderProvider(logicalaccess::LibraryManager::getInstance()->getReaderProvider(str));
    std::cout << "after..\n";
}

Build output
Building project.. [100%] Linking CXX executable bin/project CMakeFiles/project.dir/main.cpp.o: In function 'main': main.cpp:(.text+0x1ae): undefined reference to 'logicalaccess::LibraryManager::getReaderProvider(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' collect2: error: ld returned 1 exit status CMakeFiles/project.dir/build.make:191: recipe for target 'bin/project' failed make[2]: *** [bin/project] Error 1 CMakeFiles/Makefile2:95: recipe for target 'CMakeFiles/project.dir/all' failed make[1]: *** [CMakeFiles/project.dir/all] Error 2 Makefile:103: recipe for target 'all' failed make: *** [all] Error 2

CmakeLists.txt

project(project)
cmake_minimum_required(VERSION 3.16)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
set(CMAKE_CXX_FLAGS "-I /usr/include/PCSC")
add_executable(project main.cpp)
target_link_libraries(project PUBLIC CONAN_PKG::LogicalAccess)

Any advice?

@roelofd
Copy link
Author

roelofd commented May 27, 2020

I have fixed the issue. When conan is installed in the conan profile the compiler version should be changed to "compiler.libcxx=libstdc++11". This has to do with some compatibility issues with the conan compiler and cmake.

@roelofd roelofd closed this as completed May 27, 2020
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

1 participant