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

Linker error after string_view commit #1595

Open
vai-terokinnunen opened this issue Jan 13, 2025 · 0 comments
Open

Linker error after string_view commit #1595

vai-terokinnunen opened this issue Jan 13, 2025 · 0 comments

Comments

@vai-terokinnunen
Copy link

Describe the bug
Since commit 60ccc1f ("feat: support std::string_view in Value API"), simple example fails to linker error.

To Reproduce
Steps to reproduce the behavior:

  1. Install latest jsoncpp (using Ubuntu:24.04 Docker image in this test)
git clone https://github.com/open-source-parsers/jsoncpp.git
cmake -B build-jsoncpp jsoncpp
cmake --build build-jsoncpp --target install
  1. Example project:

CMakeLists.txt

project("Example")
add_executable(example main.cpp)
target_link_libraries(example jsoncpp)

main.cpp

#include <iostream>
#include <json/json.h>
int main()
{
    Json::Value root;
    root["key"] = "value";
    std::cout << root.isMember("key") << '\n';
    root.removeMember("key");
    return 0;
}
  1. Try build cmake -B build-example example && cmake --build build-example
  2. Build fails with linker error
: && /usr/bin/c++  -rdynamic CMakeFiles/example.dir/main.cpp.o -o example  -ljsoncpp && :
/usr/bin/ld: CMakeFiles/example.dir/main.cpp.o: in function `main':
main.cpp:(.text+0x6c): undefined reference to `Json::Value::operator[](std::basic_string_view<char, std::char_traits<char> >)'
/usr/bin/ld: main.cpp:(.text+0xb7): undefined reference to `Json::Value::isMember(std::basic_string_view<char, std::char_traits<char> >) const'
/usr/bin/ld: main.cpp:(.text+0x105): undefined reference to `Json::Value::removeMember(std::basic_string_view<char, std::char_traits<char> >)'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Expected behavior

  • Build successful. Works before commit 60ccc1f

Desktop (please complete the following information):

  • OS: Ubuntu 24.04
  • Meson version 1.3.2 (repeats with both meson and cmake builds)
  • Ninja version 1.11.1

Additional context

  • Extracting "key" to std::string, std::string_view or char* constant does not resolve the issue.
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

No branches or pull requests

1 participant