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

Target std::filesystem was not found (g++11) #334

Open
2 of 8 tasks
AXIHIXA opened this issue Mar 9, 2023 · 3 comments
Open
2 of 8 tasks

Target std::filesystem was not found (g++11) #334

AXIHIXA opened this issue Mar 9, 2023 · 3 comments
Labels
bug - compilation error Something isn't working cross-platform issue - linux Help wanted - Good for contributing if you are on linux

Comments

@AXIHIXA
Copy link

AXIHIXA commented Mar 9, 2023

Hi there, first of all, thanks so much for this awesome repo.

Bug category

  • bug - compilation error
  • bug - compilation warning
  • bug - runtime error
  • bug - runtime warning
  • bug - logic error

Describe the bug
Does not compile when linking against Matplot++:

CMake Error at .../Matplot++Targets.cmake:77 (set_target_properties):
  The link interface of target "Matplot++::matplot" contains:

    std::filesystem

  but the target was not found. 

Steps to Reproduce
Built with the latest release with the following commands:

cmake -B build/local \
    -DMATPLOTPP_BUILD_EXAMPLES=OFF \
    -DMATPLOTPP_BUILD_SHARED_LIBS=ON \
    -DMATPLOTPP_BUILD_TESTS=OFF \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX="$HOME/lib/Matplot++" \
    -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON
cmake --build build/local 
cmake --install build/local

Sample project (CMakeLists.txt) linking against Matplot++:

cmake_minimum_required(VERSION 3.20)
project(Matplotlib++Demo)
set(CMAKE_CXX_STANDARD 20)
find_package(Matplot++ REQUIRED HINTS "$ENV{HOME}/lib/Matplot++/lib/cmake/Matplot++/")
set(EXECUTABLE ${PROJECT_NAME})
add_executable(${EXECUTABLE} src/main.cpp)
target_link_libraries(${EXECUTABLE} Matplot++::matplot)

Output
Does not compile, no output.

Platform

  • cross-platform issue - linux
  • cross-platform issue - windows
  • cross-platform issue - macos

Environment Details:

  • OS: ubuntu
  • OS Version: 20.04
  • Compiler: g++ (from ppa:ubuntu-toolchain-r/test)
  • Compiler version: 11.1.0

Additional context
g++11 does not require a manual link against the filesystem module (it is linked automatically).
E.g., the following code compiles and runs correctly on my side:

#include <iostream>
#include <filesystem>

int main(int argc, char * argv[])
{
    std::cout << std::filesystem::current_path() << '\n';
    return 0;
}

without the need for CMake commands in the link_libraries family.

@github-actions github-actions bot added bug - compilation error Something isn't working cross-platform issue - linux Help wanted - Good for contributing if you are on linux labels Mar 9, 2023
@acxz
Copy link
Contributor

acxz commented Mar 29, 2023

I am also experiencing this issue.

@acxz
Copy link
Contributor

acxz commented Mar 31, 2023

I was able to solve the problem by using
-BUILD_SHARED_LIBS=ON \
instead of -DMATPLOTPP_BUILD_SHARED_LIBS=ON \

Looks like the following line is causing the issue:

option(MATPLOTPP_BUILD_SHARED_LIBS "Build shared libraries" ${BUILD_SHARED_LIBS})

Maybe should be
option(MATPLOTPP_BUILD_SHARED_LIBS "Build shared libraries" OFF)

@alandefreitas is this an actual issue that needs to be fixed or is the current behavior desired?

@alandefreitas
Copy link
Owner

Probably yes. It's related to this PR: #323

Although option(MATPLOTPP_BUILD_SHARED_LIBS "Build shared libraries" ${BUILD_SHARED_LIBS}) is correct. It lets the user customize it but also inherits the default behavior from the global CMake option.

The problem is that the std::filesystem interface target is not being installed in that CMake execution path. We could fix that or... since this is a C++17 library we could get rid of this target and stop supporting compilers that still don't have native std::filesystem support.

This target exists because most compilers back then supported C++17 language features but had not implemented std::filesystem yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug - compilation error Something isn't working cross-platform issue - linux Help wanted - Good for contributing if you are on linux
Projects
None yet
Development

No branches or pull requests

3 participants