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

Automate readelf and verbosity #3

Merged
merged 5 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,162 @@
# conan-cmake-playground
Some examples of Conan + CMakeDeps generators to troubleshoot linking issues


## static libraries

### old CMakeDeps

```
[100%] Linking CXX executable hello
/opt/cmake-3.30.5-linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/hello.dir/link.txt --verbose=1
/usr/bin/c++ -m64 -O3 -DNDEBUG -m64 CMakeFiles/hello.dir/print_hello.cpp.o -o hello
-L/home/memsharded/.conan2/p/b/bulba9a72ce3ac2fc9/p/lib
-L/home/memsharded/.conan2/p/b/charmed871fdc987c6/p/lib
-L/home/memsharded/.conan2/p/b/pikacee1c4113186ed/p/lib
-Wl,-rpath,/home/memsharded/.conan2/p/b/bulba9a72ce3ac2fc9/p/lib:/home/memsharded/.conan2/p/b/charmed871fdc987c6/p/lib:/home/memsharded/.conan2/p/b/pikacee1c4113186ed/p/lib
/home/memsharded/.conan2/p/b/bulba9a72ce3ac2fc9/p/lib/libbulbasaur.a
/home/memsharded/.conan2/p/b/charmed871fdc987c6/p/lib/libcharmander.a
/home/memsharded/.conan2/p/b/pikacee1c4113186ed/p/lib/libpikachu.a
```

```
Dynamic section at offset 0x2d48 contains 30 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000001d (RUNPATH) Library runpath: [/home/memsharded/.conan2/p/b/bulba9a72ce3ac2fc9/p/lib:/home/memsharded/.conan2/p/b/charmed871fdc987c6/p/lib:/home/memsharded/.conan2/p/b/pikacee1c4113186ed/p/lib]
```

### pure CMake

```
[100%] Linking CXX executable hello
/opt/cmake-3.30.5-linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/hello.dir/link.txt --verbose=1
/usr/bin/c++ -O3 -DNDEBUG CMakeFiles/hello.dir/print_hello.cpp.o -o hello
/mnt/c/Users/Diego/conanws/conan-cmake-playground/install/linux/bulbasaur/lib/libbulbasaur.a
/mnt/c/Users/Diego/conanws/conan-cmake-playground/install/linux/charmander/lib/libcharmander.a
/mnt/c/Users/Diego/conanws/conan-cmake-playground/install/linux/pikachu/lib/libpikachu.a
```

```
Dynamic section at offset 0x2d58 contains 29 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000c (INIT) 0x1000
0x000000000000000d (FINI) 0x1650
```


### incubating CMakeDeps

```
[100%] Linking CXX executable hello
/opt/cmake-3.30.5-linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/hello.dir/link.txt --verbose=1
/usr/bin/c++ -m64 -O3 -DNDEBUG -m64 CMakeFiles/hello.dir/print_hello.cpp.o -o hello
/home/memsharded/.conan2/p/b/bulba9a72ce3ac2fc9/p/lib/libbulbasaur.a
/home/memsharded/.conan2/p/b/charmed871fdc987c6/p/lib/libcharmander.a
/home/memsharded/.conan2/p/b/pikacee1c4113186ed/p/lib/libpikachu.a
```

```
Dynamic section at offset 0x2d58 contains 29 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000c (INIT) 0x1000
0x000000000000000d (FINI) 0x1650
```



## shared libraries

### old CMakeDeps

```
[100%] Linking CXX executable hello
/opt/cmake-3.30.5-linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/hello.dir/link.txt --verbose=1
/usr/bin/c++ -m64 -O3 -DNDEBUG -m64 CMakeFiles/hello.dir/print_hello.cpp.o -o hello
-L/home/memsharded/.conan2/p/b/bulbac8139c5804aac/p/lib
-L/home/memsharded/.conan2/p/b/charma6ae9001b3b66/p/lib
-L/home/memsharded/.conan2/p/b/pikaccddcbcddba2f9/p/lib
-Wl,-rpath,/home/memsharded/.conan2/p/b/bulbac8139c5804aac/p/lib:/home/memsharded/.conan2/p/b/charma6ae9001b3b66/p/lib:/home/memsharded/.conan2/p/b/pikaccddcbcddba2f9/p/lib /home/memsharded/.conan2/p/b/bulbac8139c5804aac/p/lib/libbulbasaur.so
```

```
Dynamic section at offset 0x2d50 contains 31 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libbulbasaur.so]
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000001d (RUNPATH) Library runpath: [/home/memsharded/.conan2/p/b/bulbac8139c5804aac/p/lib:/home/memsharded/.conan2/p/b/charma6ae9001b3b66/p/lib:/home/memsharded/.conan2/p/b/pikaccddcbcddba2f9/p/lib]
```


### pure CMake

```
[100%] Linking CXX executable hello
/opt/cmake-3.30.5-linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/hello.dir/link.txt --verbose=1
/usr/bin/c++ -O3 -DNDEBUG CMakeFiles/hello.dir/print_hello.cpp.o -o hello

-Wl,-rpath,/mnt/c/Users/Diego/conanws/conan-cmake-playground/install/linux/bulbasaur/lib:/mnt/c/Users/Diego/conanws/conan-cmake-playground/install/linux/charmander/lib:/mnt/c/Users/Diego/conanws/conan-cmake-playground/install/linux/pikachu/lib

/mnt/c/Users/Diego/conanws/conan-cmake-playground/install/linux/bulbasaur/lib/libbulbasaur.so

-Wl,-rpath-link,/mnt/c/Users/Diego/conanws/conan-cmake-playground/install/linux/charmander/lib:/mnt/c/Users/Diego/conanws/conan-cmake-playground/install/linux/pikachu/lib
```

```
Dynamic section at offset 0x2d50 contains 31 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libbulbasaur.so]
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000001d (RUNPATH) Library runpath: [/mnt/c/Users/Diego/conanws/conan-cmake-playground/install/linux/bulbasaur/lib:/mnt/c/Users/Diego/conanws/conan-cmake-playground/install/linux/charmander/lib:/mnt/c/Users/Diego/conanws/conan-cmake-playground/install/linux/pikachu/lib]
0x000000000000000c (INIT) 0x1000
0x000000000000000d (FINI) 0x130c
```


### incubating CMakeDeps


```
[100%] Linking CXX executable hello
/opt/cmake-3.30.5-linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/hello.dir/link.txt --verbose=1
/usr/bin/c++ -m64 -O3 -DNDEBUG -m64 CMakeFiles/hello.dir/print_hello.cpp.o -o hello
-Wl,-rpath,/home/memsharded/.conan2/p/b/bulbac8139c5804aac/p/lib:/home/memsharded/.conan2/p/b/charma6ae9001b3b66/p/lib:/home/memsharded/.conan2/p/b/pikaccddcbcddba2f9/p/lib
/home/memsharded/.conan2/p/b/bulbac8139c5804aac/p/lib/libbulbasaur.so
/home/memsharded/.conan2/p/b/charma6ae9001b3b66/p/lib/libcharmander.so
/home/memsharded/.conan2/p/b/pikaccddcbcddba2f9/p/lib/libpikachu.so
```

```
Dynamic section at offset 0x2d50 contains 31 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libbulbasaur.so]
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000001d (RUNPATH) Library runpath: [/home/memsharded/.conan2/p/b/bulbac8139c5804aac/p/lib:/home/memsharded/.conan2/p/b/charma6ae9001b3b66/p/lib:/home/memsharded/.conan2/p/b/pikaccddcbcddba2f9/p/lib]
0x000000000000000c (INIT) 0x1000
0x000000000000000d (FINI) 0x130c
```

#### LATEST PR for incubating CMakeDeps

```
[100%] Linking CXX executable hello
/opt/cmake-3.30.5-linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/hello.dir/link.txt --verbose=1
/usr/bin/c++ -m64 -O3 -DNDEBUG -m64 CMakeFiles/hello.dir/print_hello.cpp.o -o hello
-Wl,-rpath,/home/diegor/.conan2/p/b/bulbac8139c5804aac/p/lib:/home/diegor/.conan2/p/b/charma6ae9001b3b66/p/lib:/home/diegor/.conan2/p/b/pikaccddcbcddba2f9/p/lib
/home/diegor/.conan2/p/b/bulbac8139c5804aac/p/lib/libbulbasaur.so
-Wl,-rpath-link,/home/diegor/.conan2/p/b/charma6ae9001b3b66/p/lib:/home/diegor/.conan2/p/b/pikaccddcbcddba2f9/p/lib
```
6 changes: 5 additions & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import shutil

############# CONFIGURATION ###########################
shared = False
shared = True
charmander_header = False
#######################################################

Expand Down Expand Up @@ -54,6 +54,10 @@ def run(cmd):
f"-DCMAKE_INSTALL_PREFIX={install_dir}/{project} {defines} {shared_cmake} {charmander_header_cmake}")
run(f"cmake --build {build_dir}/{project} --config Release")
run(f"cmake --install {build_dir}/{project} --config Release")
if platform == "windows":
run(f"{build_dir}/squirtle/Release/hello.exe")
elif platform == "linux":
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want otool -L ... on mac for the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but I don't have a Mac to test, can be added later, this is the idea

run(f"readelf -d {build_dir}/squirtle/hello")


print("***********************************************************")
Expand Down
2 changes: 2 additions & 0 deletions projects/squirtle/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
set(CMAKE_VERBOSE_MAKEFILE ON)

cmake_minimum_required(VERSION 3.28)

project(squirtle LANGUAGES CXX)
Expand Down
17 changes: 16 additions & 1 deletion projects/squirtle/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import os

from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
from conan.tools.microsoft import VCVars


class pikachuRecipe(ConanFile):
name = "squirtle"
version = "1.0"
package_type = "application"

exports_sources = "CMakeLists.txt", "*.cpp"

# Binary configuration
settings = "os", "compiler", "build_type", "arch"
Expand All @@ -20,6 +23,18 @@ def generate(self):
deps.generate()
tc = CMakeToolchain(self)
tc.generate()
VCVars(self).generate(scope="run")

def requirements(self):
self.requires("bulbasaur/1.0")

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
exe = os.path.join(self.cpp.build.bindir, "hello")
self.run(exe, env="conanrun")
if self.settings.os == "Linux":
self.run(f"readelf -d {exe}")
if self.settings.os == "Windows":
self.run(f"dumpbin /DEPENDENTS {exe}.exe", env="conanrun")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work without having to find the tool? (i thought typically this only worked inside a vcvars environment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I explicitly added a VCVars(self).generate(scope="run") in the generate() to allow this.

1 change: 1 addition & 0 deletions projects/squirtle/print_hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <bulbasaur.h>

int main() {
std::cout << "I am squirtle!!!\n";
bulbasaur::say_hello("Ash");
return 0;
}