jtv / libpqxx

The official C++ client API for PostgreSQL.
http://pqxx.org/pqxx/
BSD 3-Clause "New" or "Revised" License
959 stars 227 forks source link

cmake will take the given lib name and it changes to "-l{libname}" and linker will search using "-l{libname}" #813

Closed srinathv2 closed 2 months ago

srinathv2 commented 2 months ago
          > cmake will take the given lib name and it changes to "-l{libname}" and linker will search using "-l{libname}"

@srinathv2 No. CMake checks if a string and the matching CMake target are defined. If a CMake target is found, it adds the necessary linker flags to use that target. If the target is not found, the name is treated as a link target.

See:

Originally posted by @tt4g in https://github.com/jtv/libpqxx/issues/383#issuecomment-2031767111

srinathv2 commented 2 months ago

@tt4g you can check this https://cmake.org/cmake/help/latest/command/target_link_libraries.html#target-link-libraries:~:text=A%20plain%20library%20name%3A%20The%20generated%20link%20line%20will%20ask%20the%20linker%20to%20search%20for%20the%20library%20(e.g.%20foo%20becomes%20%2Dlfoo%20or%20foo.lib).

tt4g commented 2 months ago

you can check this

You repeatedly asked your own question in #383, Is that comment the only one that explains the behavior I did not understand? If so, I already know its CMake behavior specification.

What I didn't understand was that find_package() should also look for libraries in the PATH environment variable, but it failed to do so. Nevertheless, when I pass only a string to target_link_libraries(), it is able to link. This is because the fact that it is linked means that libpq was found somewhere in the path contained in the PATH environment variable. This behavior appears to be inconsistent, Furthermore, find_package() could not find libpq when I defined the PostgreSQL_ROOT variable. The only way to investigate the reason for this would be to look at #383 author's machine.

srinathv2 commented 2 months ago

@tt4g this is not about any issue i was letting you know,how target_link_libraries works when you give lib name

tt4g commented 2 months ago

I don't know what you want to do by telling me that.

srinathv2 commented 2 months ago

@tt4g

What I didn't understand was that find_package() should also look for libraries in the PATH environment variable, but it failed to do so.

find_package tries to search the for -config.cmake or Config.cmake and it helps to find the lib's includes,binaries.We can specify the path to this file before find_package using set(packagename_DIR path),i agree it searches for the Config.cmake file in this order CMAKE_PREFIX_PATH,PATH you can check https://cmake.org/cmake/help/latest/command/find_package.html#search-procedure how find_package searches for the config file

srinathv2 commented 2 months ago

I don't know what you want to do by telling me that.

@tt4g i saw the comment https://github.com/jtv/libpqxx/issues/383#issuecomment-723992584 and just thought to help and learn,nothing else.

tt4g commented 2 months ago

Suddenly such a comment is lost on me. Because you were commenting on how to link a customized libpq just prior to that.