Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Linking Issue #49

Open
samielhini opened this issue Mar 12, 2018 · 38 comments
Open

Linking Issue #49

samielhini opened this issue Mar 12, 2018 · 38 comments

Comments

@samielhini
Copy link

I am almost certain I am doing something wrong.

I do not get this error for luna::server but when I reference luna::router I get the following during linking:

CMakeFiles/GlacierHardwareController.dir/Webserver.cpp.o: In function Webserver::Webserver(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)': /home/sami.elhini/Code/glacierhardwarecontrollerv2/Webserver.cpp:13: undefined reference to luna::router::router(std::__cxx11::basic_string<char, std::char_traits, std::allocator >)'
collect2: error: ld returned 1 exit status
CMakeFiles/GlacierHardwareController.dir/build.make:307: recipe for target 'bin/GlacierHardwareController' failed
make[2]: *** [bin/GlacierHardwareController] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/GlacierHardwareController.dir/all' failed
make[1]: *** [CMakeFiles/GlacierHardwareController.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

CMakeLists.txt Excerpt:

set(CMAKE_CXX_STANDARD 14)
if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
else()
message(WARNING "The file conanbuildinfo.cmake doesn't exist, you have to run conan install first")
endif()

target_link_libraries(GlacierHardwareController ${LIBS} ${CONAN_LIBS})

Code Excerpt:

Webserver::Webserver(const int port, const std::string directory) {
this->port = port;
luna::router rtr("/");
//luna::router router{"/"};
//assets.serve_files("/", directory);
//srv.add_router(assets);
}

void Webserver::run(){

srv.start(this->port);

}

conanfile.txt

[requires]
luna/4.0.0@DEGoodmanWilson/stable
nl-json/2.1.1@genvidtech/1.4.0

[generators]
cmake

@DEGoodmanWilson
Copy link
Owner

Ok that’s weird! I’ll look into that, thanks for raising it!

@samielhini
Copy link
Author

samielhini commented Mar 12, 2018

Definitely. I really like your coding style and would be thrilled to get this working. I suppose I can experiment with a project with fewer dependencies. I have a fair number of CMAKE dependencies. I would think namespaces would avoid collisions and it is bizarre that only that class does not seem to produce a linkable symbol. Could it be a C dependency without an extern "C" block?

@samielhini
Copy link
Author

samielhini commented Mar 12, 2018

stdint.h is included by types.h. Types.h does not have it in an extern C block and stdint.h does not seem to have an extern C block either. Just a thought.

@samielhini
Copy link
Author

Reproduced with a totally clean project with no other dependencies. See attached.

TestLuna.zip

@DEGoodmanWilson
Copy link
Owner

Will work on replicating and fixing this morning. Thank you for the replication case!

@DEGoodmanWilson
Copy link
Owner

Could you tell me what OS and compiler you are using, BTW?

@DEGoodmanWilson
Copy link
Owner

Just to eliminate some possibilities, let's do this to your conanfile. At the moment, the only version of Luna that stands a change of compiling is 5.0.0. 4.0.0 won't fly. Change your conanfile to look like this:

[requires]
luna/5.0.0@samielhini/testing

[generators]
cmake

Now, go clone the Luna repo to your local machine, and inside the luna directory, do this:

git checkout 5.0.0/testing
conan create . samielhini/testing

This will put a private build on your machine so you can tinker with Luna locally, and have those changes reflected in your test program. Every time you make a change to luna, just re-run the conan create … command.

As it stands, like this, I get one build error right off the bat, that I am going to submit a fix for now, a missing header file in the package deployment!

@DEGoodmanWilson
Copy link
Owner

OK, that build error is fixed, and with those changes to the conanfile, I am able to get your sample compiling, linking, and running under OS X.

@samielhini
Copy link
Author

I will give it a try. I am on Debian 9. I actually do all my other coding work on a Mac but use Debian when I work on my embedded code.

@samielhini
Copy link
Author

Quite strange:

canning dependencies of target TestLuna
[ 50%] Building CXX object CMakeFiles/TestLuna.dir/main.cpp.o
[100%] Linking CXX executable bin/TestLuna
CMakeFiles/TestLuna.dir/main.cpp.o: In function main': /home/sami.elhini/Code/TestLuna/main.cpp:8: undefined reference to luna::router::router(std::__cxx11::basic_string<char, std::char_traits, std::allocator >)'
/home/sami.elhini/Code/TestLuna/main.cpp:9: undefined reference to `luna::router::serve_files(std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >)'
collect2: error: ld returned 1 exit status
CMakeFiles/TestLuna.dir/build.make:94: recipe for target 'bin/TestLuna' failed
make[3]: *** [bin/TestLuna] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/TestLuna.dir/all' failed
make[2]: *** [CMakeFiles/TestLuna.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/TestLuna.dir/rule' failed
make[1]: *** [CMakeFiles/TestLuna.dir/rule] Error 2
Makefile:118: recipe for target 'TestLuna' failed
make: *** [TestLuna] Error 2

I will note that I had to use --build missing with my Conan install file for CMake.

@DEGoodmanWilson
Copy link
Owner

That's super weird. Do you have, or can you recommend, a Docker image or other VM image that I can use to try to replicate your environment? It looks like symbols aren't getting exported from the Luna library…

@samielhini
Copy link
Author

samielhini commented Mar 16, 2018 via email

@DEGoodmanWilson
Copy link
Owner

👍

@DEGoodmanWilson
Copy link
Owner

Latest push of 5.0.0/testing is a big improvement. Precompiled binaries are even available if you clear our your conan cache! But there is a problem, in that you'll get a nasty runtime error the first time you try to serve an endpoint:

libc++abi.dylib: terminating with unexpected exception of type std::runtime_error: Invalid mime database filename provided: /Users/travis/.conan/data/mime-db/1.33.0/DEGoodmanWilson/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/res/db.json

This is a problem with libmime and/or conan-mime-db, and I'm now seeking help from the conan folks on this:

conan-io/conan#2626

@DEGoodmanWilson
Copy link
Owner

ok @samielhini everything seems to be working now! Try your sample program again, and let me know how it works.

@samielhini
Copy link
Author

Does this error make any sense to you:

/home/sami.elhini/Code/TestLuna/main.cpp:8:27: error: ‘luna::router::router(std::__cxx11::string)’ is protected within this context
luna::router router{"/"};

@DEGoodmanWilson
Copy link
Owner

Yes. The API for creating router objects has changed. Sorry ;)

You now create a router like this:

auto router = server.create_router("/");

the router instance is now a pointer, so you'll need to use router->handle_request() instead of router.handle_request().

@samielhini
Copy link
Author

samielhini commented Mar 21, 2018 via email

@DEGoodmanWilson
Copy link
Owner

Hrm, I need more context. Can you share with me what your main.cpp looks like?

@samielhini
Copy link
Author

samielhini commented Mar 21, 2018 via email

@DEGoodmanWilson
Copy link
Owner

Hrm, there's a couple of things that might be going on. Can you do this for me?

conan remove luna/*
conan remove base64/*
conan remove gmp/*
conan remove jsonformoderncpp/*
conan remove libgpg-error/*
conan remove libiconv/*
conan remove mime-db/*
conan remove zlib/*
conan remove libgcrypt/*
conan remove libmime/*
conan remove nettle/*
conan remove gnutls/*
conan remove libmicrohttpd/*

to clear our the conan cache, then try a conan install . again?

@DEGoodmanWilson
Copy link
Owner

This might be easier to copy and paste:

conan remove -f luna/*
conan remove -f base64/*
conan remove -f gmp/*
conan remove -f jsonformoderncpp/*
conan remove -f libgpg-error/*
conan remove -f libiconv/*
conan remove -f mime-db/*
conan remove -f zlib/*
conan remove -f libgcrypt/*
conan remove -f libmime/*
conan remove -f nettle/*
conan remove -f gnutls/*
conan remove -f libmicrohttpd/*

@samielhini
Copy link
Author

samielhini commented Mar 21, 2018 via email

@DEGoodmanWilson
Copy link
Owner

OK, I can replicate in a Docker container based on lasote/conangcc6, I'll spend some time staring this down! Something isn't getting linked right…

@DEGoodmanWilson
Copy link
Owner

Going to try to bring in a little help in solving this mystery: conan-io/conan#2658

@DEGoodmanWilson
Copy link
Owner

OK, @samielhini try this:

Clear our your conan cache again. then:
conan install . -s compiler.libcxx=libstdc++11

let me know how that works!

@samielhini
Copy link
Author

samielhini commented Mar 24, 2018 via email

@DEGoodmanWilson
Copy link
Owner

Doesn't matter where you do the removal from. Can you send me the output of running
conan profile show default ?

@samielhini
Copy link
Author

samielhini commented Mar 24, 2018 via email

@DEGoodmanWilson
Copy link
Owner

Ok. Last thing: can you verify that you removed gnutls/*?

@samielhini
Copy link
Author

samielhini commented Mar 26, 2018 via email

@DEGoodmanWilson
Copy link
Owner

OK, TBH I'm at a bit of a loss. I've tried this now in a docker container (based on lasote/conangcc60, and I cannot replicate. Which is why I'm scratching my head, as the difference must be in something about the conan configuration, or the CMake configuration.

After re-running conan install… did you force CLion to reload the CMakeLists.txt?

Can you try removing all the intermediate CMake files? *.cmake, CMakeCache.txt, CMakeFiles/, cmake-build-debug/, everything that CMake / CLion generate, and try from the command line?

Failing that, would you mind taking the rather drastic step of removing also ~/.conan as well, and seeing if that helps?

@DEGoodmanWilson
Copy link
Owner

@samielhini One other thing you can try is building with these commands:

conan install . -s compiler.libcxx=libstdc++11
cmake . -DCONAN_LIBCXX=libstdc++11
cmake --build .

to force the right standard library. Let me know how this is working for you.

@samielhini
Copy link
Author

samielhini commented Mar 27, 2018 via email

@DEGoodmanWilson
Copy link
Owner

We’ll get this working one way or another! Hang in there.

@samielhini
Copy link
Author

samielhini commented Mar 27, 2018 via email

@DEGoodmanWilson
Copy link
Owner

Closing, stale. Reopen if the problem comes back up!

@DEGoodmanWilson
Copy link
Owner

This problem reared it's head again in #74

It appears that some kernel versions don't provide the getrandom function that gnutls relies on.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants