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

Problem: absolute path inside dylib (fix #123) #124

Closed
wants to merge 1 commit into from

Conversation

leejw51crypto
Copy link
Collaborator

Solution: remove absolute path, use relative path instead

@damoncro
Copy link
Contributor

damoncro commented Jun 23, 2022

Does user still need to copy to /usr/local/lib?

@damoncro
Copy link
Contributor

Maybe tag a temporary version and test the binary release.

@leejw51crypto
Copy link
Collaborator Author

leejw51crypto commented Jun 24, 2022

nope , don't need /usr/local/lib
i'll tag and test binary
test would be like this
otool -L , check whether libplay_cpp_sdk starts with @rpath (previously, it was compiling computer's absolute path)

install_name_tool -id @rpath/libplay_cpp_sdk.dylib ./libplay_cpp_sdk.dylib
otool -L ./libplay_cpp_sdk.dylib

@@ -40,6 +40,8 @@ jobs:
cp ./LICENSE build
cp ./CHANGELOG.md build
cd build
install_name_tool -id @rpath/libplay_cpp_sdk.dylib ./lib/libplay_cpp_sdk.dylib
Copy link
Contributor

@damoncro damoncro Jun 24, 2022

Choose a reason for hiding this comment

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

Modifying the path in packing probably has a side effect: the binary was not tested in integration test.

It is better to modify the build.rs or setup .cargo/config and pass the the option to compiler: rust-lang/cargo#5077

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok, i'm checking now

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

checked with tag, now released with @rpath like this

 otool -L libplay_cpp_sdk.dylib
libplay_cpp_sdk.dylib:
	@rpath/libplay_cpp_sdk.dylib (compatibility version 0.0.0, current version 0.0.0)

@leejw51crypto
Copy link
Collaborator Author

leejw51crypto commented Jun 24, 2022

after using @rpath,
export DYLD_LIBRARY_PATH=$(PWD)/lib && ./demo
user need to run like this on mac, and need to add rpath in user's executive binary.

in packaged app, libplay_cpp_sdk.dylib should be copied in app's default rpath

ref: https://users.rust-lang.org/t/need-help-linking-to-third-party-dynamic-library/47817

it's only mac specific, windows searches dll from the same folder with exe, PATH etc.. , in order

demo/Makefile Outdated
@@ -53,9 +53,14 @@ dynamic: easywsclient.o
$(FLAGS) \
-L lib \

x86_64_build: prepare_x86_64 easywsclient.o.x86_64
x86_64_run: x86_64_build
export DYLD_LIBRARY_PATH=$(PWD)/lib && ./demo
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be tested in CI?

Copy link
Contributor

@damoncro damoncro Jun 24, 2022

Choose a reason for hiding this comment

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

I agree dylib should be copied into @rpath. We build in g++, unfortunately it is not an app bundle. Override DYLD_LIBRARY_PATH seems can not verify rpath works. So how about setup LD_RUNPATH_SEARCH_PATH (not tested) instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok, i'll add to mac-build.yml , checking whether dynamic dylib can be called correctly

Copy link
Contributor

Choose a reason for hiding this comment

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

Tested LD_RUNPATH_SEARCH_PATH, can not work..

Copy link
Contributor

@damoncro damoncro Jun 24, 2022

Choose a reason for hiding this comment

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

Passing -rpath lib to g++ can fix the issue. No need to export env.

	g++ -o demo \
		easywsclient.o \
		main.cc \
		chainmain.cc \
		cronos.cc \
		extra.cc \
		include/*.cc \
		include/extra-cpp-bindings/src/*.cc \
		include/defi-wallet-core-cpp/src/*.cc \
		lib/libcxxbridge1.a \
		-lplay_cpp_sdk \
		-std=c++14 \
		$(FLAGS) \
		-rpath lib \
		-L lib \

Copy link
Contributor

@damoncro damoncro Jun 24, 2022

Choose a reason for hiding this comment

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

So unreal and g++ can both use the same rpath setting like you mentioned before.

 otool -L libplay_cpp_sdk.dylib
libplay_cpp_sdk.dylib:
	@rpath/libplay_cpp_sdk.dylib (compatibility version 0.0.0, current version 0.0.0)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

add rlib option and also comment, too.

@leejw51crypto leejw51crypto force-pushed the feature/123 branch 2 times, most recently from 7659c7d to 8063ece Compare June 24, 2022 05:16
demo/Makefile Outdated
@@ -53,9 +53,14 @@ dynamic: easywsclient.o
$(FLAGS) \
-L lib \

x86_64_build: prepare_x86_64 easywsclient.o.x86_64
x86_64_test_dylib:
export DYLD_LIBRARY_PATH=$(PWD)/lib && ./demo test
Copy link
Contributor

Choose a reason for hiding this comment

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

No need DYLD_LIBRARY_PATH?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok, i'll remove it

@leejw51crypto leejw51crypto force-pushed the feature/123 branch 2 times, most recently from 036aa61 to 6b71dc0 Compare June 24, 2022 05:25
@@ -40,6 +40,8 @@ jobs:
cp ./LICENSE build
cp ./CHANGELOG.md build
cd build
install_name_tool -id @rpath/libplay_cpp_sdk.dylib ./lib/libplay_cpp_sdk.dylib
Copy link
Contributor

@damoncro damoncro Jun 24, 2022

Choose a reason for hiding this comment

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

if we pack @rpath in CI for users, the binary will be used in demo (starts from a clean repository clone), so we should keep consistent in the setup:

  1. https://github.com/cronos-labs/play-cpp-sdk/blob/main/README.md?plain=1#L60 is no longer needed.
  2. https://github.com/cronos-labs/play-cpp-sdk/blob/main/README.md?plain=1#L64 make should work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, i'll modify

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i think libplay_cpp_sdk.dylib should be delivered with @rpath, because it is not system dylib.
it will be invalid in user's envrironment.

README.md Outdated
``` sh
cd demo
cp lib/libplay_cpp_sdk.dylib /usr/local/lib
cp lib/libplay_cpp_sdk.dylib $HOME/lib
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Of course, it is ok to add a new $HOME/lib and export it with DYLD_LIBRARY_PATH. It is still a workaround... Ideally, most users just simply run the program in terminal (like other programs) without touching the env.

Copy link
Collaborator Author

@leejw51crypto leejw51crypto Jun 24, 2022

Choose a reason for hiding this comment

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

ok, i'll removed it, now just make will work

@leejw51crypto leejw51crypto force-pushed the feature/123 branch 4 times, most recently from 37316dd to e63c990 Compare June 24, 2022 08:39
README.md Outdated
4. Under `demo` folder and build the `demo` project
``` sh
make
2. or Unzip the archive file into `demo` folder
Copy link
Contributor

Choose a reason for hiding this comment

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

why or?

Copy link
Contributor

@damoncro damoncro Jun 24, 2022

Choose a reason for hiding this comment

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

After cloning the repository, demo folder doesn't have the include and lib folder, it is a must to unzip the folders and files into demo folder.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

git clone or unzip the archive file

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, but archive file here refers to the https://github.com/cronos-labs/play-cpp-sdk/blob/main/README.md?plain=1#L25, not the source codes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or did I get the wrong thing?

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't that git clone first, then unzip for example play_cpp_sdk_Darwin_x86_64.tar.gz?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, git clone then unzip or untar,
modified

@leejw51crypto leejw51crypto force-pushed the feature/123 branch 3 times, most recently from d78a0c0 to 189b950 Compare June 24, 2022 10:33
@leejw51crypto
Copy link
Collaborator Author

copy to /usr/local/lib not necessary

@leejw51crypto
Copy link
Collaborator Author

separated mac build test, and checking now

@leejw51crypto leejw51crypto force-pushed the feature/123 branch 2 times, most recently from e1616f9 to 9cd3cf5 Compare June 24, 2022 16:01
@leejw51crypto
Copy link
Collaborator Author

leejw51crypto commented Jun 24, 2022

fixed bug in Makefile (in flags..) (no \ before $(FALGS) )

@leejw51crypto leejw51crypto force-pushed the feature/123 branch 3 times, most recently from 74ce1ef to 536b841 Compare June 27, 2022 04:34
@damoncro
Copy link
Contributor

damoncro commented Jun 30, 2022

dylib linking is incorrect, I am checking. run make or make x86_64_build or make build in demo

include/extra-cpp-bindings/src/lib.rs.cc:1199:58: error: cannot initialize a variable of type 'void (com::crypto::game_sdk::WalletConnectCallback::*)(::std::unique_ptr< ::com::crypto::game_sdk::WalletConnectSessionInfo>) const' with an rvalue of type 'void (com::crypto::game_sdk::WalletConnectCallback::*)(const com::crypto::game_sdk::WalletConnectSessionInfo &) const': type mismatch at 1st parameter ('::std::unique_ptr< ::com::crypto::game_sdk::WalletConnectSessionInfo>' (aka 'unique_ptr<com::crypto::game_sdk::WalletConnectSessionInfo>') vs 'const com::crypto::game_sdk::WalletConnectSessionInfo &')
  void (::com::crypto::game_sdk::WalletConnectCallback::*onConnected$)(::std::unique_ptr<::com::crypto::game_sdk::WalletConnectSessionInfo>) const = &::com::crypto::game_sdk::WalletConnectCallback::onConnected;
                                                         ^                                                                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/extra-cpp-bindings/src/lib.rs.cc:1204:58: error: cannot initialize a variable of type 'void (com::crypto::game_sdk::WalletConnectCallback::*)(::std::unique_ptr< ::com::crypto::game_sdk::WalletConnectSessionInfo>) const' with an rvalue of type 'void (com::crypto::game_sdk::WalletConnectCallback::*)(const com::crypto::game_sdk::WalletConnectSessionInfo &) const': type mismatch at 1st parameter ('::std::unique_ptr< ::com::crypto::game_sdk::WalletConnectSessionInfo>' (aka 'unique_ptr<com::crypto::game_sdk::WalletConnectSessionInfo>') vs 'const com::crypto::game_sdk::WalletConnectSessionInfo &')
  void (::com::crypto::game_sdk::WalletConnectCallback::*onDisconnected$)(::std::unique_ptr<::com::crypto::game_sdk::WalletConnectSessionInfo>) const = &::com::crypto::game_sdk::WalletConnectCallback::onDisconnected;
                                                         ^                                                                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/extra-cpp-bindings/src/lib.rs.cc:1209:58: error: cannot initialize a variable of type 'void (com::crypto::game_sdk::WalletConnectCallback::*)(::std::unique_ptr< ::com::crypto::game_sdk::WalletConnectSessionInfo>) const' with an rvalue of type 'void (com::crypto::game_sdk::WalletConnectCallback::*)(const com::crypto::game_sdk::WalletConnectSessionInfo &) const': type mismatch at 1st parameter ('::std::unique_ptr< ::com::crypto::game_sdk::WalletConnectSessionInfo>' (aka 'unique_ptr<com::crypto::game_sdk::WalletConnectSessionInfo>') vs 'const com::crypto::game_sdk::WalletConnectSessionInfo &')
  void (::com::crypto::game_sdk::WalletConnectCallback::*onConnecting$)(::std::unique_ptr<::com::crypto::game_sdk::WalletConnectSessionInfo>) const = &::com::crypto::game_sdk::WalletConnectCallback::onConnecting;
                                                         ^                                                                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/extra-cpp-bindings/src/lib.rs.cc:1214:58: error: cannot initialize a variable of type 'void (com::crypto::game_sdk::WalletConnectCallback::*)(::std::unique_ptr< ::com::crypto::game_sdk::WalletConnectSessionInfo>) const' with an rvalue of type 'void (com::crypto::game_sdk::WalletConnectCallback::*)(const com::crypto::game_sdk::WalletConnectSessionInfo &) const': type mismatch at 1st parameter ('::std::unique_ptr< ::com::crypto::game_sdk::WalletConnectSessionInfo>' (aka 'unique_ptr<com::crypto::game_sdk::WalletConnectSessionInfo>') vs 'const com::crypto::game_sdk::WalletConnectSessionInfo &')
  void (::com::crypto::game_sdk::WalletConnectCallback::*onUpdated$)(::std::unique_ptr<::com::crypto::game_sdk::WalletConnectSessionInfo>) const = &::com::crypto::game_sdk::WalletConnectCallback::onUpdated;
                                                         ^                                                                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 errors generated.
make: *** [dynamic] Error 1
make  15.95s user 2.48s system 86% cpu 21.210 total


- name: Build demo project
working-directory: demo
run: make x86_64_build_test
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this command run in mac-build.yml?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, i'll move it

# install_name_tool -add_rpath @executable_path/lib ./demo
# in mac, to use DYLD_LIBRARY_PATH, it is normalized to use $rpath in dylib
x86_64_build_dynamic : prepare_x86_64 easywsclient.o.x86_64
install_name_tool -id @rpath/libplay_cpp_sdk.dylib ./lib/libplay_cpp_sdk.dylib
Copy link
Contributor

Choose a reason for hiding this comment

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

g++ has -install_name option.

@leejw51crypto
Copy link
Collaborator Author

ok, i'll fix

@leejw51crypto
Copy link
Collaborator Author

leejw51crypto commented Jun 30, 2022

x86_64_build

checked on apple m1

could you clone again?
run make cppx86_64 ?

i think lib.rs.cc is not copied from target correctly.

@damoncro
Copy link
Contributor

damoncro commented Jun 30, 2022

In #129, there may be some conflicts:

  1. Integrate x86_64 and amd64 into one Makefile entry
  2. Modify the rpath in Makefile as make build, so that we can pack the library after testing in ci.
  3. Integrate cmake workflow, including dynamic build
  4. Integrate examples into cmake to make use the dynamic library
  5. move the bindings and library into sdk folder for easy packing and have better support in cmake (with add_subdirectory)

add x86_64 dylib build

update Makefile

test dylib works

fix main

reformat

add rpath option

add rpath comment

 add more comment

remove un-necessary

change readme

make simple

add or

typo

add or for windows

restore readme

untar

restore

disable test

separate test

change name

tidyup test

fix compile option

add comment

remove mac-test
@leejw51crypto
Copy link
Collaborator Author

rebased

@leejw51crypto
Copy link
Collaborator Author

leejw51crypto commented Jun 30, 2022

In #129, there may be some conflicts:

  1. Integrate x86_64 and amd64 into one Makefile entry
  2. Modify the rpath in Makefile as make build, so that we can pack the library after testing in ci.
  3. Integrate cmake workflow, including dynamic build
  4. Integrate examples into cmake to make use the dynamic library
  5. move the bindings and library into sdk folder for easy packing and have better support in cmake (with add_subdirectory)

ok, i'll rebase
if #129, uses @rpath, #129 also closes this issue.
this pr not necessary

@damoncro
Copy link
Contributor

it still has problems on crypto-com/defi-wallet-core-rs#461, it is better to rebase after both finish...

@damoncro
Copy link
Contributor

Ok, I will fix rapth in #129

@leejw51crypto
Copy link
Collaborator Author

thanks , after #129 merged, i'll close this one.

@tomtau
Copy link
Contributor

tomtau commented Jul 13, 2022

#129 was merged, so closing this one

@tomtau tomtau closed this Jul 13, 2022
@leejw51crypto leejw51crypto deleted the feature/123 branch April 26, 2024 03:30
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

Successfully merging this pull request may close these issues.

3 participants