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

[bug] Packages linked with static libraries cannot be used in editable mode #13543

Closed
Todiq opened this issue Mar 27, 2023 · 3 comments · Fixed by #13544
Closed

[bug] Packages linked with static libraries cannot be used in editable mode #13543

Todiq opened this issue Mar 27, 2023 · 3 comments · Fixed by #13544
Assignees
Labels
Milestone

Comments

@Todiq
Copy link
Contributor

Todiq commented Mar 27, 2023

Environment details

  • Operating system: Rocky Linux 8.7
  • Compiler: GCC 8.5.0
  • Conan version: 2.0.2
  • Python version: 3.9.13

Steps to reproduce

Create a package A in a folder

Copy the following conanfile.py

from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
from conan.tools.env import Environment, VirtualBuildEnv, VirtualRunEnv
from conan.tools.files import copy, collect_libs

class Pkg(ConanFile):
	required_conan_version = ">=1.50.0"
	name = "A"
	version = "1.0"

	# Binary configuration
	settings = "os", "compiler", "build_type", "arch"
	options = {
		"shared": [True, False],
		"fPIC": [True, False],
	}
	default_options = {
		"shared": False,
		"fPIC": True,
	}

	def export_sources(self):
		copy(self, "*.c*", src=self.recipe_folder, dst=self.export_sources_folder)
		copy(self, "*CMakeLists.txt", src=self.recipe_folder, dst=self.export_sources_folder)

	def build_requirements(self):
		self.test_requires("gtest/1.13.0")

	def config_options(self):
		if self.settings.os == "Windows":
			del self.options.fPIC

	def layout(self):
		cmake_layout(self)

	def generate(self):
		vr = VirtualRunEnv(self)
		vr.generate()
		ct = CMakeToolchain(self)
		ct.generate()
		cd = CMakeDeps(self)
		cd.generate()

	def build(self):
		cmake = CMake(self)
		cmake.configure()
		cmake.build()

Copy the following CMakeLists.txt

cmake_minimum_required(VERSION 3.23)

set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_STANDARD 17)
set(PROJECT_NAME test)

project(${PROJECT_NAME} LANGUAGES CXX)

find_package(GTest)

add_library(${PROJECT_NAME})

target_sources(${PROJECT_NAME}
	PRIVATE
		a.cpp
)

target_link_libraries(${PROJECT_NAME}
	PRIVATE
		gtest::gtest
)

Copy the following source file a.cpp

#include <gtest/gtest.h>

std::string	hello()
{
	return "Hello";
}

TEST(testMath, test_hello)
{
    EXPECT_EQ("Hello", hello());
}

Run the following command :

conan build . -verror --settings "&:build_type=Debug" --options="A/*:shared=True" --build=missing

A libtest.so is successfully created in build/Debug. It is linked with a static version of gtest.

Mark the reciped as editable with

conan editable add .

The command returns

Reference 'A/1.0' in editable mode

Create a package B in another folder

Copy the following conanfile.py

from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
from conan.tools.env import Environment, VirtualBuildEnv, VirtualRunEnv
from conan.tools.files import copy, collect_libs

class Pkg(ConanFile):
	required_conan_version = ">=1.50.0"
	name = "B"
	version = "1.0"

	# Binary configuration
	settings = "os", "compiler", "build_type", "arch"
	options = {
		"shared": [True, False],
		"fPIC": [True, False],
	}
	default_options = {
		"shared": False,
		"fPIC": True,
	}

	def export_sources(self):
		copy(self, "*.c*", src=self.recipe_folder, dst=self.export_sources_folder)
		copy(self, "*CMakeLists.txt", src=self.recipe_folder, dst=self.export_sources_folder)

	def requirements(self):
		self.requires("A/1.0")
	def config_options(self):
		if self.settings.os == "Windows":
			del self.options.fPIC

	def layout(self):
		cmake_layout(self)

	def generate(self):
		vr = VirtualRunEnv(self)
		vr.generate()
		ct = CMakeToolchain(self)
		ct.generate()
		cd = CMakeDeps(self)
		cd.generate()

	def build(self):
		cmake = CMake(self)
		cmake.configure()
		cmake.build()

Copy the following CMakeLists.txt

cmake_minimum_required(VERSION 3.23)

set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_STANDARD 17)
set(PROJECT_NAME test)

project(${PROJECT_NAME} LANGUAGES CXX)

add_executable(${PROJECT_NAME})

target_sources(${PROJECT_NAME}
	PRIVATE
		b.cpp
)

Copy the following source file b.cpp

int	main()
{
	return 0;
}

Run the command

conan build . -verror --settings "&:build_type=Debug" --build=missing

The following error shows up:

ERROR: A/1.0: Error in generate() method, line 49
        cd.generate()
        ConanException: error generating context for 'gtest/1.13.0': include is not absolute

Expected results : Package B should compile without any issue.

From my understanding, this happens whenever a shared library links with a static one. Compiling gtest as a shared library fixes the issue. However, gtest is usually compiled as a static library.

The issue also happens:

  • While using Boost as a dependency and compiled as a shared library. I get the same error with libbacktrace, even though it is not a direct dependency of my project (but used by Boost).
  • With any non direct dependency that I didn't specify to be built as shared ones.

Might be another bug : self.options does not affect packages added with test_requirements. (e.g: gtest)

@Todiq Todiq changed the title [bug] Packages linking with static libraries cannot be used in editable mode [bug] Packages linked with static libraries cannot be used in editable mode Mar 27, 2023
@memsharded memsharded self-assigned this Mar 27, 2023
@memsharded
Copy link
Member

Hi @Todiq

Thanks very much for your detailed report. I am having a look.

Quick side feedback:

  • Package names in Conan 2.0 must be all lowercase and contain more than 1 letter. This doesn't launch an error at the moment for editables, but it might launch it at anytime. You can see the error if you try to conan create
  • The required_conan_version = ">=1.50.0" is not a class attribute, in order to work you need to put it outside the class, at the file level.

@memsharded
Copy link
Member

Your reproducible case really helped to reproduce, thanks very much again for such a reduced and clean repro case.
Indeed a bug, the deps of "editable" packages could be skipped, I am proposing a fix for next 2.0.3 in #13544

AbrilRBS added a commit that referenced this issue Mar 27, 2023
Changelog: Bugfix: Avoid generators errors because dependencies binaries
of editable packages were "skip"
Docs: Omit

Close #13543
@memsharded
Copy link
Member

Closed by #13544, it will be released in next 2.0.3, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants