Compiling a program on linux.

Aug 5, 2014 at 5:22 PM
So I managed to compile this on windows and I'm not too familiar with compilation on linux, just learning to work on a linux platform really. Anyway I sucessfully built the sdk on linux and passed all tests sucessfully.

However I go to compile the program on linux which is a short program and it spits an overflowing ammount of errors at me. Not too sure on this one.

command I'm using: gcc -std=c++11 -o Realms RealmStatusMain.cpp -I/home/granda/casablanca/Release/include/ -lboost -lcasablanca

I can post the errors too, but Im hoping its as simple as me incorrectly using a command because the errors are so numerous.

Thanks,
Granda
Aug 5, 2014 at 6:28 PM
Edited Aug 5, 2014 at 6:34 PM
Hi Granda,

Your issue is that you link boost before you link Casablanca. You need to exchange the "-lboost" and "-lcasablanca" options to the gcc line.

Please see the following two discussions for more information:
https://casablanca.codeplex.com/discussions/542485
https://casablanca.codeplex.com/discussions/558306

If this doesn't solve the issue, could you please post the details of your situation (Distro version, gcc version, architecture, the exact errors you get, what version of boost you have)?

Thanks,
roschuma

Edit: Also, you should probably be using g++ instead of gcc.
Aug 5, 2014 at 8:52 PM
Edited Aug 5, 2014 at 9:08 PM
The linking order didn't solve it even while switching to g + + 4.8 so here is the information you requested, thanks for responding so quickly:

Linux ubuntu 14.04 lts x64

boost version: 1.54.0-4ubuntu3.1

g++ 4.8

Command: g++-4.8 -std=c++11 -o Realms RealmStatusMain.cpp -I/home/granda/casablanca/Release/include/ -lcasablanca -lboost

The errors are too long to post here, heres a couple snippets:
RealmStatusMain.cpp: In function ‘pplx::task<void> WoWRealmCheck(std::wstring&)’:
RealmStatusMain.cpp:18:46: error: no matching function for call to ‘web::uri_builder::uri_builder(const wchar_t [21])’
  uri_builder uribuild(L"http://us.battle.net");
                                              ^
RealmStatusMain.cpp:18:46: note: candidates are:
In file included from /home/granda/casablanca/Release/include/cpprest/uri.h:34:0,
                 from /home/granda/casablanca/Release/include/cpprest/http_msg.h:43,
                 from /home/granda/casablanca/Release/include/cpprest/http_client.h:47,
                 from RealmStatusMain.cpp:1:
/home/granda/casablanca/Release/include/cpprest/uri_builder.h:56:9: note: web::uri_builder::uri_builder(const web::uri&)
         uri_builder(const uri &uri_str): m_uri(uri_str.m_components) {}
         ^
/home/granda/casablanca/Release/include/cpprest/uri_builder.h:56:9: note:   no known conversion for argument 1 from ‘const wchar_t [21]’ to ‘const web::uri&’
/home/granda/casablanca/Release/include/cpprest/uri_builder.h:50:9: note: web::uri_builder::uri_builder()
         uri_builder() {}


---------------------------------------------------------


RealmStatusMain.cpp: In lambda function:
RealmStatusMain.cpp:39:39: error: no matching function for call to ‘web::json::value::has_field(const wchar_t [7]) const’
    std::wcout << v.has_field(L"realms") << std::endl;
                                       ^
RealmStatusMain.cpp:39:39: note: candidate is:
In file included from /home/granda/casablanca/Release/include/cpprest/http_msg.h:42:0,
                 from /home/granda/casablanca/Release/include/cpprest/http_client.h:47,
                 from RealmStatusMain.cpp:1:
/home/granda/casablanca/Release/include/cpprest/json.h:1720:17: note: bool web::json::value::has_field(const string_t&) const
     inline bool json::value::has_field(const utility::string_t& key) const
                 ^
/home/granda/casablanca/Release/include/cpprest/json.h:1720:17: note:   no known conversion for argument 1 from ‘const wchar_t [7]’ to ‘const string_t& {aka const std::basic_string<char>&}’
RealmStatusMain.cpp:40:50: error: passing ‘const web::json::value’ as ‘this’ argument of ‘web::json::value& web::json::value::at(size_t)’ discards qualifiers [-fpermissive]
    const web::json::value realms = v.at(L"realms");
                                                  ^
RealmStatusMain.cpp:40:50: error: invalid conversion from ‘const wchar_t*’ to ‘size_t {aka long unsigned int}’ [-fpermissive]
In file included from /home/granda/casablanca/Release/include/cpprest/http_msg.h:42:0,
                 from /home/granda/casablanca/Release/include/cpprest/http_client.h:47,
                 from RealmStatusMain.cpp:1:
/home/granda/casablanca/Release/include/cpprest/json.h:455:34: error:   initializing argument 1 of ‘web::json::value& web::json::value::at(size_t)’ [-fpermissive]
         _ASYNCRTIMP json::value& at(size_t index);

Aug 7, 2014 at 4:23 PM
Switching from wide chars doesn't resolve the issues either.
Aug 7, 2014 at 10:35 PM
Edited Aug 7, 2014 at 10:36 PM
What do you mean switching from wide chars?

Ideally, you should replace all instances of L"xyz" with U("xyz"). This will select either L"xyz" (on windows) or "xyz" (on non-windows) which corresponds with the preferred string type on the system (UTF-8 vs UTF-16).

If this doesn't fix the issues, could you try using pastebin for the error log? Alternatively, if you don't mind making your source code available (via codeplex, github, or similar), I can give a more detailed diagnostic.

Edit: You may also need to replace instances of std::string with utility::string_t
Aug 7, 2014 at 11:15 PM
Errors Pastebin: http://pastebin.com/FipiAAx9

As for the source, I definitely don't mind making it available, this was just supposed to be something simple to help learn the API and it worked fine on windows, I'm just not used to compiling on a linux machine and dealing with portability which is showing for me.

Source Pastebin:

http://pastebin.com/qBebNPHq
Aug 7, 2014 at 11:22 PM
It looks like you forgot parentheses with the U macro.

For example:

uri_builder uribuild(U"http://us.battle.net");

should be

uri_builder uribuild(U("http://us.battle.net"));
Aug 8, 2014 at 4:01 PM
That I did, thanks it solved all the large error text from streaming out now the only issue is its saying it can't locate lib casablanca and boost.

:

/usr/bin/ld: cannot find -lcasablanca
/usr/bin/ld: cannot find -lboost
collect2: error: ld returned 1 exit status


I'll work on getting that fixed.
Aug 8, 2014 at 8:53 PM
So after routing around for a while, it looks like there is no libcasablanca on my computer, after searching around various folders for an .so or .a for libcasablanca and using the locate command nothing turned up which seems weird.
Aug 8, 2014 at 9:49 PM
Ah, yes. You'll need to add a library path to your link command in order to link against Casablanca. Assuming you've used the Linux instructions to the letter, try

g++-4.8 -std=c++11 -o Realms RealmStatusMain.cpp -I/home/granda/casablanca/Release/include/ -L/home/granda/casablanca/Release/build.release/Binaries -lcpprest -lboost

I've also replaced -lcasablanca with -lcpprest since the old library name is deprecated.
Marked as answer by GrandaThePanda on 8/10/2014 at 10:24 PM
Aug 8, 2014 at 10:25 PM
Edited Aug 8, 2014 at 10:28 PM
Ok at first libboost was not found replacing lboost with lboost_system allowed compilation, upon running the application though, gave this error, ./Realms: error while loading shared libraries: libcpprest.so.2.1: cannot open shared object file: No such file or directory

I think I can add that to linux environment... with no success, I did:

echo $LD_LIBRARY_PATH which produced nothing so;

I added the default path $LD_LIBRARY_PATH = /usr/local/lib
then added the path to my file: LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/granda/casablanca/Release/build.release/Binaries/libcpprest.so.2.1
exported it, export LD_LIBRARY_PATH

and ran the program again, ./Realms

which produced the same error about the missing file

I also checked the symlink from the libcpprest.so and it is pointing at the correct file.

Edit: I also ran ldconfig to see if it would make a difference, which it did not.
Aug 8, 2014 at 11:39 PM
Try setting LD_LIBRARY_PATH=. and copying libcpprest.so.2.1 to the same directory as your application (Realms?).
Aug 9, 2014 at 5:36 AM
Edited Aug 10, 2014 at 10:19 AM
That still resulted in the library not being found, using /path/to/lib --library-path ./realms allowed it to run, which seg faulted. I've included a link to the original version of the code that compiled and ran on windows as I'm confused to why this isn't working.

Original: http://pastebin.com/kRR79H0A

Current: http://pastebin.com/qBebNPHq

Update: running with sudo prevents the fault, but the program hangs.

Update 2: I copied the example from the getting started tutorial, compiled using the earlier solution for compilation, that went fine. However, running it produced the same library not found mark which I solved using the same method above, which then produced a seg fault, running it with sudo took care of the segfault and the program ran, but produced no text output or the search file it is supposed to create and then exited.
Aug 11, 2014 at 5:37 AM
It runs on my machine doing the following:
  • Build Casablanca in ~/casablanca/build.debug
  • Paste the "Current" source in ~/granda/Realms.cpp
  • Replace the instances of U"hello, world" with U("hello, world")
  • Build with the command "g++ Realms.cpp -L ~/casablanca/build.debug/Binaries -lcpprest -lboost_system -I ~/casablanca/Release/include -std=c++11"
  • Copy the libcpprest.so.2.1 from ~/casablanca/build.debug/Binaries to ~/granda
  • Run with the command "LD_LIBRARY_PATH=. ./a.out"
It prompts for "Enter realm name:" and then does the usual connect when given input.

Does that work for you?
Marked as answer by GrandaThePanda on 8/10/2014 at 10:23 PM
Aug 11, 2014 at 6:23 AM
Skipped to the last step, running in my projects folder and worked fine. Thanks a lot for all the input.