casbin/casbin-cpp

File casbin.a not found in usr/local/lib

noob20000405 opened this issue · 13 comments

Hi, I just locally installed casbin-cpp following : https://github.com/casbin/casbin-cpp#installation-and-set-up. However the file casbin.a is found in

/home/username/casbin-cpp/build/casbin/casbin.a 

(OS : ubuntu 20.04)
which is supposed to be found in usr/local/lib.

I'm not sure if it's the reason of my question following :

I tried to compile my test file by

g++ -std=c++17 test.cpp -o test

but I always get the following no matter where I put casbin.a (usr/local/lib or not)

/usr/bin/ld: /tmp/ccPdK9Y2.o: in function `IsAuthorized()':
test.cpp:(.text+0xa9): undefined reference to `casbin::Enforcer::Enforcer(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: test.cpp:(.text+0x21b): undefined reference to `casbin::Enforcer::Enforce(std::initializer_list<std::variant<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::shared_ptr<casbin::ABACData> > > const&)'
/usr/bin/ld: /tmp/ccPdK9Y2.o: in function `casbin::Enforcer::~Enforcer()':
test.cpp:(.text._ZN6casbin8EnforcerD2Ev[_ZN6casbin8EnforcerD5Ev]+0x13): undefined reference to `vtable for casbin::Enforcer'
collect2: error: ld returned 1 exit status

That would be great if you would give me some ideas about how to fix it.
Sorry for the long question, thank you in advance.

@noob20000405 It seems that the docs haven't been updated. When you build the install target, CMake makes this target "visible"/"available" to all the other CMake projects on your machine. i.e. you can just find_package(casbin) into your main CMakeLists.txt file to use the targets.

Look at: https://github.com/casbin/casbin-cpp#with-local-installation

And the binaries will be available at <custom-path>/casbin-cpp/build/casbin/casbin.a and the headers at ${CMAKE_INSTALL_PREFIX}/include.

It seems that the docs haven't been updated.

@EmperorYP7 can we update the docs?

@EmperorYP7 Thanks for your reply, it works. But I still met something unexpected :
I have to replace casbinTargets.cmake by casbin-config.cmake at casbin-cpp/CMakeLists.txt (Ln. 102) to make it works.
Otherwise, seems that the package casbin can't be found in my project :

  By not providing "Findcasbin.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "casbin", but
  CMake did not find one.

  Could not find a package configuration file provided by "casbin" with any
  of the following names:

    casbinConfig.cmake
    casbin-config.cmake

  Add the installation prefix of "casbin" to CMAKE_PREFIX_PATH or set
  "casbin_DIR" to a directory containing one of the above files.  If "casbin"
  provides a separate development package or SDK, be sure it has been
  installed.

I'm not sure it's a problem or it was me who made some mistakes. Thanks anyway in advance.

@EmperorYP7 can we update the docs?

Sure! 😄

@noob20000405 I think you should refer to this: https://cliutils.gitlab.io/modern-cmake/chapters/install/exporting.html

You will find a proprietary file generated at $HOME/.cmake/packages once you build the install target correctly. If you don’t see any file in that location, something went wrong during the export. Also, digging through the build logs might be helpful if the issue isn’t resolve.

@noob20000405 any update?

@sheny1xuan can you update the docs ? https://github.com/casbin/casbin-cpp#installation-and-set-up

Of course, I will do it latter.

@EmperorYP7 Thanks for your reply, it works. But I still met something unexpected : I have to replace casbinTargets.cmake by casbin-config.cmake at casbin-cpp/CMakeLists.txt (Ln. 102) to make it works. Otherwise, seems that the package casbin can't be found in my project :

  By not providing "Findcasbin.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "casbin", but
  CMake did not find one.

  Could not find a package configuration file provided by "casbin" with any
  of the following names:

    casbinConfig.cmake
    casbin-config.cmake

  Add the installation prefix of "casbin" to CMAKE_PREFIX_PATH or set
  "casbin_DIR" to a directory containing one of the above files.  If "casbin"
  provides a separate development package or SDK, be sure it has been
  installed.

I'm not sure it's a problem or it was me who made some mistakes. Thanks anyway in advance.

I met this this problem too. Should we change casbinTargets.cmake by casbin-config.cmake or casbinConfig.cmake?
Because Cmake try to find <Packagename>Config.cmake in its stored directory. Ref to the cmake document. @EmperorYP7

export(PACKAGE <PackageName>)
Store the current build directory in the CMake user package registry for package . The find_package() command may consider the directory while searching for package . This helps dependent projects find and use a package from the current project’s build tree without help from the user. Note that the entry in the package registry that this command creates works only in conjunction with a package configuration file (Config.cmake) that works with the build tree. In some cases, for example for packaging and for system wide installations, it is not desirable to write the user package registry.

@sheny1xuan try changing the name to casbinConfig.cmake here.

Does it solve the issue?

@sheny1xuan try changing the name to casbinConfig.cmake here.

Does it solve the issue?

Yes, It works. And I will make a PR for that latter.

🎉 This issue has been resolved in version 1.39.4 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀