Project

General

Profile

newbie Linux developer help building Wt hello example please

Added by Zalu Hobgobicus over 12 years ago

Hello,

I am a developer who is excited about adopting Linux C Wt development, but I am coming from Windowsland and don't know of any better place to learn what I assume are some basic missing skills for learning how to build projects, because I have been trying many things to build the basic Hello Wt example, and am still stuck.

I understand some of the basics of command-line compiling and linking C programs using gcc and even a hand-written makefile, and I understand that CMake can generate a makefile, and I think I get that this is generally done by typing "make foo" from above the directory foo.

I am running the latest version of Ubuntu, and I have installed g and Aptitude and the Wt development package using:

sudo aptitude install witty witty-dbg witty-dev witty-doc

Which seemed to work fine.

I have been following the Wt Tutorial PDF and I think it is inaccurate on at least one point. It says that:

"On UNIX-like systems, you could do the following:

$ g -o hello hello.cc -lwthttp -lwt

$ ./hello ---docroot . ---http-address 0.0.0.0 ---http-port 9090"

But there is no hello.cc file, and g will stop, complaining it doesn't exist. There is a hello.C file, but

g -o hello hello.C -lwthttp -lwt

results in complaints about either permissions (if I try to run not as root in the place the demo code got installed), or complaints about undefined Boost references (after I moved the examples to a directory my account owns).

So far I think things make good-enough sense. I think I'm supposed to copy the code to my own dev folder before building it, and then the linker will need to know where Boost is. But I don't know where to point it, nor do I know the best way(s) (or any way, short of lots of hunting and trial and error) to get the linker pointed to Boost. I assume I could either provide the path to Boost in a file so g will always try there, which I'd like, or I need to supply it in a makefile or command-line parameters to the linker. I have little good idea how to find the right path to give, where to put the path, or what the syntax of the path would be.

I see that hello.C manages to reference the Wt libraries, I assume by its installer having managed to have -lwthttp -lwt mean something to g, but then the Boost libs that it also seems to need are not getting linked. hello.C only mentions Wt, so I assume it's finding Wt libs but not Boost libs, which seems odd and likely difficult to find without help, since that linkage is probably inside the Wt libs or setup somewhere and it's all new to me. I wouldn't want to go insert some hard-fought hack which doesn't really solve the real issue.

I also see that there is a CMakeLists.txt file in the hello directory, and that it has places to insert paths as they exist on my system. This looks like the right place because it says:

\"#

  1. If you have Wt installed somehwere, you should use the
  2. installed Wt header files for your own Wt projects.
  3. e.g. INCLUDE_DIRECTORIES(/usr/local/include)
  4. instead of the following:
    #
    INCLUDE_DIRECTORIES(${WT_INCLUDE_DIR})
    TARGET_LINK_LIBRARIES(hello.wt ${SSL_LIBRARIES} ${BOOST_WT_LIBRARIES} ${BOOST_WTHTTP_LIBRARIES} ${ZLIB_LIBRARIES} ${ASIO_LIBRARIES})\"

However I am not certain if I am supposed to edit this file and replace all six DIR and LIBRARIES strings with the actual paths on my machine (which I'm supposed to figure out by searching my file system?) or if those are environment variables to set in some other config file?

I also notice that if I try going above my own copy of the Hello demo and typing the command "make hello" that make says \"Nothing to be done for 'hello'. I would sort of expect it to complain about the paths to the libs being wrong or something.

Anyway, I think I'm on the right tracks, but I also think I am now guessing what I need to do next, and I expect either there's a great answer to this somewhere already, or else the answer will be useful to others, so I wrote this question this way.

Thanks for any help!

Zalu


Replies (11)

RE: newbie Linux developer help building Wt hello example please - Added by Zalu Hobgobicus over 12 years ago

Helping myself a bit, I re-found this page with some instructions:

http://www.webtoolkit.eu/wt/doc/reference/html/InstallationUnix.html

I had seen this before but forgot about it as I started working with the tutorial PDF instead, which is where I got stuck.

I am now seeing how far these get me.

RE: newbie Linux developer help building Wt hello example please - Added by Zalu Hobgobicus over 12 years ago

Ok, so I am stopped at step 1 of the installation instructions, where it says:

"The recommended way to build the library is in a seperate build directory, for example within the top-level of the Wt package:

$ cd wt-x.xx

$ mkdir build

$ cd build"

I assume, by exploring the file system manually, that "the top-level of the Wt package" is the folder I found under /usr/lib/Wt?

So I went there in terminal, and typed "cd wt-x.xx", and was told it doesn't exist. Ok, so I suppose wt-x.xx is code for something, and/or I guessed wrong about what "the top-level of the Wt package" means, or both.

RE: newbie Linux developer help building Wt hello example please - Added by Zalu Hobgobicus over 12 years ago

So, is step 1 above saying I should go into the /usr/lib/Wt/examples/hello directory, and make a build folder there, and go into it? Step 2 is to run "cmake ../". I tried this, but had to do sudo mkdir, and sudo cmake, which despite being sudo sent me various no-permissions errors, as well as nonexistent directory errors, and it looks like I still need to go edit the makelists file paths to the libs manually? It doesn't seem like the installation instructions or the tutorial suggest one needs to do that, unless that's just supposed to be understood by anyone trying to build a Linux project?

Help?

RE: newbie Linux developer help building Wt hello example please - Added by Аз Есмь over 12 years ago

hello and welcome, Zalu!

i think you should first decide which version of Wt you need to use:

a) installing from source:

  • the latest, newest, but unstable version from git;
  • the latest stable version from SourceForge [currently, 3.2.2 patch-level 1];

b) installing from packages:

  • a reasonably recent version from Pau Garcia's PPA repository [currently, 3.2.1];
  • a not so recent version from the Ubuntu repository [currently, 3.1.10 for Precise Pangolin, and 3.2.1 for upcoming Quantal Quetzal].

good luck

RE: newbie Linux developer help building Wt hello example please - Added by Zalu Hobgobicus over 12 years ago

Thanks Аз Есмь.

I think stability and ease of getting things configured correctly are my priorities, latest and newest is probably not important at all to me, and instability would be confusing/discouraging/time-wasting if I ran into it, so installing from packages seems good, and that's what I did, following the page at redmine.webtoolkit.eu/wiki/1/Installing_Wt_on_Ubuntu which had me install using the Aptitude package i.e. "aptitude install witty witty-dbg witty-dev witty-doc".

That seems to have worked and I can run the examples but not build them, due to not knowing how to use the makefiles, since I am new to working with c projects on Linux and have little practical knowledge of how to respond to errors or troubleshoot things, understand conventions and so on.

I am going to give up on the first two documents for now, and move on to the third document I found trying to help people build Wt, which is the Redmine document titled "Using Make" at http://redmine.webtoolkit.eu/wiki/1/Using_CMake .

RE: newbie Linux developer help building Wt hello example please - Added by Аз Есмь over 12 years ago

i think i now understand what you've been meaning to achieve. correct me if i'm wrong, but you wanted to install Wt first and then build the hello example as a stand-alone project.

if that's your plan then you can't use CMakeLists.txt in the hello directory which is shipped with the Wt sources, as it's meant to be used only when building ALL the examples.

as to the problem of undefined references, you have to make sure all the required libraries are installed and they're listed in the command. so if you get something like this:

'boost::signals::detail::slot_base::create_connection()' is defined in DSO /usr/lib/libboost_signals.so.1.46.1

then you should add -lboost_signals to the list of libraries. thus your command gets like this:

g -o hello hello.C -lwthttp -lwt -lboost_signals

if you got other complaints, please let us see them.

and it's better not to put your sources into /usr as that's a system directory and requires administrator'su privieges [sudo] to change.

RE: newbie Linux developer help building Wt hello example please - Added by Zalu Hobgobicus over 12 years ago

Thanks again Аз Есмь!

Yes, I want to develop my own site (build a server, not a CGI plugin, at this point anyway), and it looks like the Hangman example would be a great starting place (though I will probably end up replacing the mySql with a Membase, but that's a future concern). So I wanted to be able to start by building the examples, and then be able to develop them into my own projects.

Thank you so much for the information that the CMakeLists are designed to build all of the examples, as that isn't something I'll want for my own projects.

And thank you so very much for the information about how to add a library to a build command like that. I was afraid I was going to have to insert paths into the CMakeLists files.

Ok, I will try this out now...

RE: newbie Linux developer help building Wt hello example please - Added by Zalu Hobgobicus over 12 years ago

HOORAY!

Thank you, Аз Есмь!

Ok, wonderful, I built hello in my own folder, using a command-line like you suggested!

What I wonder, though, is how someone is supposed to know to type \"lboost_signals\" when the error message complains about "libboost_signals" where would I go to translate the error message into the actual needed lib name (lboost... vs. libboost...)?

I am very happy to have gotten past this, and to see it is not as fiddly as it was starting to seem!

RE: newbie Linux developer help building Wt hello example please - Added by Аз Есмь over 12 years ago

i'm very glad that you're very happy and my reply was helpful to you.

you can find details about that weird linking practice in many places of the Web. here's a couple of links, to begin with:

http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html#index-Libraries-1013

http://tinf2.vub.ac.be/\~dvermeir/manual/uintro/gpp.html#tth_sEc3.2

please don't be so afraid of CMakeLists. they're friends to many developers, including Wt ones. and i encourage you to study the article about using CMake which you've already started to read.

for instance, you can use CMake to build the hello example as well. firstly, replace the original CMakeLists.txt file in the hello directory with a new one containing this:

ADD_EXECUTABLE(hello hello.C)

TARGET_LINK_LIBRARIES(hello wthttp wt boost_signals)

INCLUDE_DIRECTORIES(${WT_INCLUDE_DIR})

lastly, run the following commands:

cmake .

make

and you'll get almost the same result as with g++ -o hello hello.C -lwthttp -lwt -lboost_signals. the difference is that the directory will be infested with various CMake assisting files.

of course, one can hardly see here any advantages from using CMake, but as your project grows CMake might become invaluable to you.

good luck.

RE: newbie Linux developer help building Wt hello example please - Added by Zalu Hobgobicus over 12 years ago

Thanks again, Аз Есмь!

Getting through to building makes a huge difference. Thanks for the further tips and links, too.

I am not sure if I will use CMake, or write a makefile myself, but certainly one or the other will become very handy as the project grows.

    (1-11/11)