Code Monkey home page Code Monkey logo

Comments (10)

ben-crowhurst avatar ben-crowhurst commented on July 19, 2024 3

Please try the following

g++  -std=c++11 -g -I"/usr/local/lib/restbed/distribution/include" example.cpp -o example -L"/usr/local/lib/restbed/distribution/library" -lrestbed

G++ linking options

from restbed.

ben-crowhurst avatar ben-crowhurst commented on July 19, 2024

Hi glederrey,

#include </usr/local/lib/restbed/build/librestbed.so>

Is not a vaild means of linking a library with a C/C++ based compiler. Before proceeding any further would you please provide us with the output of the following command.

g++ --version

from restbed.

glederrey avatar glederrey commented on July 19, 2024

Hi,

Okay.. I knew that I was doing something wrong..

Here is the output of the command g++ --version:

g++ (Ubuntu 4.9.2-0ubuntu1~14.04) 4.9.2 Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

from restbed.

glederrey avatar glederrey commented on July 19, 2024

Hi,

I'm a little bit closer now.. I now use a makefile to link the library. Here it is:

ifndef RESTBED_MODULES_PATH
export RESTBED_MODULES_PATH=/usr/local/lib/restbed
endif

INCLUDE = -I"$(RESTBED_MODULES_PATH)/distribution/include"
LIBRARIES = -L"$(RESTBED_MODULES_PATH)/distribution"

CC=gcc
CXX=g++  -Wno-unused-result -std=c++11
RM=rm -f
CPPFLAGS=-c -Wall
LDFLAGS=-g $(INCLUDE)
LDLIBS=$(LIBRARIES)

SOURCES=example.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=example

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
    $(CXX) $(LDFLAGS) $(OBJECTS) -o $@ $(LDLIBS)

.cpp.o:
    $(CXX) $(LDFLAGS) $(CPPFLAGS) $< -o $@ $(LDLIBS)

clean:
    $(RM) $(OBJECTS) $(EXECUTABLE)

And if I compile using the command make, I have this error:

g++  -Wno-unused-result -std=c++11 -g -I"/usr/local/lib/restbed/distribution/include" -c -Wall example.cpp -o example.o -L"/usr/local/lib/restbed/distribution"
g++  -Wno-unused-result -std=c++11 -g -I"/usr/local/lib/restbed/distribution/include" example.o -o example -L"/usr/local/lib/restbed/distribution"
example.o: In function `operator()':
/home/gael/Desktop/restbed-test/example.cpp:20: undefined reference to `restbed::Session::close(int, std::string const&, std::multimap<std::string, std::string, std::less<std::string>, std::allocator<std::pair<std::string const, std::string> > > const&)'
example.o: In function `get_method_handler(std::shared_ptr<restbed::Session> const&)':
/home/gael/Desktop/restbed-test/example.cpp:10: undefined reference to `restbed::Session::get_request() const'
/home/gael/Desktop/restbed-test/example.cpp:13: undefined reference to `restbed::Request::get_header(std::string const&, unsigned long&, unsigned long) const'
/home/gael/Desktop/restbed-test/example.cpp:21: undefined reference to `restbed::Session::fetch(unsigned long, std::function<void (std::shared_ptr<restbed::Session> const&, std::vector<unsigned char, std::allocator<unsigned char> > const&)> const&)'
example.o: In function `main':
/home/gael/Desktop/restbed-test/example.cpp:27: undefined reference to `restbed::Resource::set_path(std::string const&)'
/home/gael/Desktop/restbed-test/example.cpp:28: undefined reference to `restbed::Resource::set_method_handler(std::string const&, std::function<void (std::shared_ptr<restbed::Session> const&)> const&)'
/home/gael/Desktop/restbed-test/example.cpp:31: undefined reference to `restbed::Settings::set_port(unsigned short)'
/home/gael/Desktop/restbed-test/example.cpp:32: undefined reference to `restbed::Settings::set_default_header(std::string const&, std::string const&)'
/home/gael/Desktop/restbed-test/example.cpp:34: undefined reference to `restbed::Service::Service()'
/home/gael/Desktop/restbed-test/example.cpp:35: undefined reference to `restbed::Service::publish(std::shared_ptr<restbed::Resource const> const&)'
/home/gael/Desktop/restbed-test/example.cpp:36: undefined reference to `restbed::Service::start(std::shared_ptr<restbed::Settings const> const&)'
/home/gael/Desktop/restbed-test/example.cpp:34: undefined reference to `restbed::Service::~Service()'
/home/gael/Desktop/restbed-test/example.cpp:34: undefined reference to `restbed::Service::~Service()'
example.o: In function `_ZN9__gnu_cxx13new_allocatorIN7restbed8ResourceEE9constructIS2_IEEEvPT_DpOT0_':
/usr/include/c++/4.9/ext/new_allocator.h:120: undefined reference to `restbed::Resource::Resource()'
example.o: In function `_ZN9__gnu_cxx13new_allocatorIN7restbed8SettingsEE9constructIS2_IEEEvPT_DpOT0_':
/usr/include/c++/4.9/ext/new_allocator.h:120: undefined reference to `restbed::Settings::Settings()'
collect2: error: ld returned 1 exit status
make: *** [example] Error 1

from restbed.

glederrey avatar glederrey commented on July 19, 2024

Hi,

I just changed a little bit the makefile like this:

ifndef RESTBED_MODULES_PATH
export RESTBED_MODULES_PATH=/usr/local/lib/restbed
endif

INCLUDE = -I"$(RESTBED_MODULES_PATH)/distribution/include/"
LIBRARIES = -L"$(RESTBED_MODULES_PATH)/distribution/library" -lrestbed

CC=gcc
CXX=g++  -Wno-unused-result -std=c++11
RM=rm -f
CPPFLAGS=-c -Wall
LDFLAGS=-g $(INCLUDE)
LDLIBS=-g $(LIBRARIES)

SOURCES=example.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=example

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
    $(CXX) $(LDFLAGS) $(OBJECTS) -o $@ $(LDLIBS)

.cpp.o:
    $(CXX) $(LDFLAGS) $(CPPFLAGS) $< -o $@ $(LDLIBS)

clean:
    $(RM) $(OBJECTS) $(EXECUTABLE)

And it compile now.. But I still have a problem when I try to run the program:

gael@mint-gael ~/Desktop/restbed-test $ ./example
./example: error while loading shared libraries: librestbed.so: cannot open shared object file: No such file or directory

If I try your command, it says:
g++: error: example.o: No such file or directory

from restbed.

ben-crowhurst avatar ben-crowhurst commented on July 19, 2024

Please set-up your Linux environment with:

LD_LIBRARY_PATH="/usr/local/lib/restbed/distribution/library"

from restbed.

glederrey avatar glederrey commented on July 19, 2024

It worked!! Thank you so much!!

If I can suggest you something, it would be really great if you can add an example of a Makefile or the command to compile your library.. It would prevent having some issues like mine.. =)

Thanks a lot again..

from restbed.

ben-crowhurst avatar ben-crowhurst commented on July 19, 2024

Will look into creating a template.

We love hearing how people are using Restbed. What awesome project are you building?

from restbed.

glederrey avatar glederrey commented on July 19, 2024

I'm working for a company called nViso.. We work on analysing faces to detect emotions.. If you want more information, you can take a look at our website: http://nviso.ch/.. And we're using restbed because we have a REST API for our product..

Thanks again for your help..

I give you my Makefile if you want to start with this:

### WARNING: If librestbed.so cannot be found, use the foloowing command: 
###
### export LD_LIBRARY_PATH=/usr/local/lib/restbed/distribution/library
###

ifndef RESTBED_MODULES_PATH
export RESTBED_MODULES_PATH=/usr/local/lib/restbed
endif

INCLUDE = -I"$(RESTBED_MODULES_PATH)/distribution/include/"
LIBRARIES = -L"$(RESTBED_MODULES_PATH)/distribution/library" -lrestbed

CC=gcc
CXX=g++  -Wno-unused-result -std=c++11 -fuse-ld=bfd
RM=rm -f
CPPFLAGS=-c -Wall
LDFLAGS=-g $(INCLUDE)
LDLIBS=$(LIBRARIES)

SOURCES=example.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=example

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
    $(CXX) $(LDFLAGS) $(OBJECTS) -o $@ $(LDLIBS)

.cpp.o:
    $(CXX) $(LDFLAGS) $(CPPFLAGS) $< -o $@ $(LDLIBS)

clean:
    $(RM) $(OBJECTS) $(EXECUTABLE)

from restbed.

ben-crowhurst avatar ben-crowhurst commented on July 19, 2024

Exciting stuff, we wish you all the best. If you require any further help don't hesitate to contact the team.

from restbed.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.