aisouard / libwebrtc

:package: Google's WebRTC implementation in a single static library.
https://axel.isouard.fr/libwebrtc
Apache License 2.0
641 stars 190 forks source link

Issue building c project with LibWebRTC #51

Closed CharlieHollow closed 7 years ago

CharlieHollow commented 7 years ago

Hi,

I'm working with WebRTC on Ubuntu 16.04, installed as you explain.

My problem is when I try to build client peerconnection with cmake, I get:

webrtcbridge_node.cc:(.text+0x41): undefined reference to `gtk_init'
webrtcbridge_node.cc:(.text+0xee): undefined reference to `GtkMainWnd::GtkMainWnd(char const*, > int, bool, bool)' 
webrtcbridge_node.cc:(.text+0xfd): undefined reference to `GtkMainWnd::Create()'
webrtcbridge_node.cc:(.text+0x148): undefined reference to`PeerConnectionClient::PeerConnectionClient()' 
webrtcbridge_node.cc:(.text+0x1fa): undefined reference to`GtkMainWnd::Destroy()' 
webrtcbridge_node.cc:(.text+0x222): undefined reference to `PeerConnectionClient::~PeerConnectionClient()'
webrtcbridge_node.cc:(.text+0x24f): undefined reference to `GtkMainWnd::~GtkMainWnd()'
webrtcbridge_node.cc:(.text+0x29c): undefined reference to `PeerConnectionClient::~PeerConnectionClient()'
webrtcbridge_node.cc:(.text+0x2d8): undefined reference to `GtkMainWnd::~GtkMainWnd()'

This is my CMakeLists.txt

cmake_minimum_required(VERSION 3.3)
project(webrtcbridge)

add_compile_options(-std=c++11)

find_package(LibWebRTC REQUIRED)
include (${LIBWEBRTC_USE_FILE})

find_package(PkgConfig REQUIRED) 
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)

include_directories(${GTK3_INCLUDE_DIRS})
link_directories(${GTK3_LIBRARY_DIRS})

add_executable(${PROJECT_NAME}_node src/webrtcbridge_node.cc)

target_link_libraries(${PROJECT_NAME}_node
  ${LIBWEBRTC_LIBRARIES}
)

target_link_libraries(${PROJECT_NAME}_node
  ${GTK_LIBRARIES}
)

Trying to find out where is the problem, I've tried to build with gcc, and when I use pkg-config with LibWebRTC, it returns this error:

Error: -lwebrtc not found (which is in pkg-config --libs) and I dont know exactly how to fix this.

Any idea? Thanks

aisouard commented 7 years ago

Hello,

For the GTK issue, could you try with ${GTK3_LIBRARIES} instead of ${GTK_LIBRARIES} ? For the pkg-config issue, I'm not sure, please run the pkg-config --list-all command and tell me if you can see LibWebRTC in the list by pasting the whole line, the spelling might be wrong.

CharlieHollow commented 7 years ago

Hi @aisouard,

thank you so much for your answer.

In first place, I've tried ${GTK3_LIBRARIES} instead of ${GTK_LIBRARIES}and it fixed that dependence.

About LibWebRTC, I 've run on terminal $ pkg-config --list-all | grep LibWebRTC and I got:

LibWebRTC - Google's native WebRTC implementation shipped into a single library

So, in effect, pkg-config recognizes it.

I run on terminal: $ pkg-config --libs LibWebRTC and I got:

-L/usr/local/lib -lwebrtc -lSM -lICE -lX11 -lXext -ldl -lrt

and the problem, I think, could be in -lwebrtc, because trying to build the client with gcc, gcc could not locate that library

aisouard commented 7 years ago

Perhaps you should try with g++, are you sure that libwebrtc.a is located inside the /usr/local/lib folder ?

CharlieHollow commented 7 years ago

I'm using cmake to build my project anyway.

And libwebrtc.a is in ~/libwebrtc/out/lib which is the installation folder. But when I run $ sudo make install it did not install the library in /usr/local/lib folder, so I supposed it was in the correct location

Edit: I have copied libwebrtc.a in /usr/local/lib and the problem persists

agouaillard commented 7 years ago

if -lwebrtc does not work it means at least one of the following: 1 - "webrtc" is the wrong spelling for your lib (often) 2 - "webrtc" is the right spelling, but the lib has different arch (rare, and usually triggers a different error message) 3 - the lib is not in your LIBPATH (most likely)

the fastest way to check if you have the right lib is to manually relocate the lib in the build_directory of your cmake project. If your project is made of multiple sub directories, it will be in the build directory corresponding to the sub directory of the CMakeLists.txt which called "add_executable" on the target linking libwebrtc, with respect to the root, i.e. the top-most CMakeLists.txt used by the current cmake process.

you move the lib there, if it compiles, the lib itself is ok in terms of architecture, symbols contained, and naming, and you have a LIBPATH problem.

On Tue, Aug 29, 2017 at 5:29 PM, CharlieHollow notifications@github.com wrote:

I'm using cmake to build my project anyway.

And libwebrtc.a is in ~/libwebrtc/out/lib which is the installation folder. But when I run $ sudo make install it did install the library in /usr/local/lib folder, so I supposed it was in the correct location

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/aisouard/libwebrtc/issues/51#issuecomment-325608743, or mute the thread https://github.com/notifications/unsubscribe-auth/AAT1nsv5tmfaE8RqXvwECrMAvWUcy1jTks5sc9oDgaJpZM4PEeRn .

-- Alex. Gouaillard, PhD, PhD, MBA

President - CoSMo Software Consulting, Singapore

sg.linkedin.com/agouaillard

-

CharlieHollow commented 7 years ago

Hi @agouaillard, thanks for your answer as well.

I'm not secure what do you mean in your first option. The name of the library is libwebrtc.a, as is defined by default.

About third option, I've relocated the library in build folder and other folders as well with no result.

Even I've tried to add to CMakeList.txt this lines to link the library:

link_directories(~/libwebrtc/out/lib)

target_link_libraries(${PROJECT_NAME}_node libwebrtc.a)

but it does not fix the problem either.

CharlieHollow commented 7 years ago

Hi again @aisouard @agouaillard,

finally I solved these problems, adding some missing libraries as JSONCPP and missing files as main_wnd.cc, conductor.cc, etc.

However, I'm still getting this error, due to one or two missing libraries I think, but I can't find them out.

CMakeFiles/webrtcbridge_node.dir/src/webrtcbridge_node.cc.o:(.rodata._ZTI18CustomSocketServer[_ZTI18CustomSocketServer]+0x10): undefined reference to `typeinfo for rtc::PhysicalSocketServer'
CMakeFiles/webrtcbridge_node.dir/src/conductor.cc.o: In function`Conductor::OnMessageFromPeer(int, std::string const&)':
conductor.cc:(.text+0x294d): undefined reference to `rtc::GetStringFromJsonObject(Json::Value const&, std::string const&, std::string*)' 
conductor.cc:(.text+0x2aed): undefined reference to`rtc::GetStringFromJsonObject(Json::Value const&, std::string const&, std::string*)' 
conductor.cc:(.text+0x2f46): undefined reference to`rtc::GetStringFromJsonObject(Json::Value const&, std::string const&, std::string*)'
conductor.cc:(.text+0x2fa7): undefined reference to`rtc::GetIntFromJsonObject(Json::Value const&, std::string const&, int*)'
conductor.cc:(.text+0x3004): undefined reference to `rtc::GetStringFromJsonObject(Json::Value const&, std::string const&, std::string*)' 
CMakeFiles/webrtcbridge_node.dir/src/peer_connection_client.cc.o:(.rodata._ZTI20PeerConnectionClient[_ZTI20PeerConnectionClient]+0x28): undefined reference to`typeinfo for rtc::MessageHandler'

Which could be these libraries? Or it is another problem?

Thanks again.

agouaillard commented 7 years ago

webrtc/rtc_base/json.cpp

On Fri, Sep 8, 2017 at 10:37 AM, CharlieHollow notifications@github.com wrote:

Hi again @aisouard https://github.com/aisouard @agouaillard https://github.com/agouaillard,

finally I solved these problems, adding some missing libraries as JSONCPP and missing files as main_wnd.cc, conductor.cc, etc.

However, I'm still getting this error, due to one or two missing libraries I think, but I can't find them out.

CMakeFiles/webrtcbridge_node.dir/src/webrtcbridge_node.cc.o:(.rodata._ZTI18CustomSocketServer[_ZTI18CustomSocketServer]+0x10): undefined reference to typeinfo for rtc::PhysicalSocketServer' CMakeFiles/webrtcbridge_node.dir/src/conductor.cc.o: In functionConductor::OnMessageFromPeer(int, std::string const&)': conductor.cc:(.text+0x294d): undefined reference to rtc::GetStringFromJsonObject(Json::Value const&, std::string const&, std::string*)' conductor.cc:(.text+0x2aed): undefined reference tortc::GetStringFromJsonObject(Json::Value const&, std::string const&, std::string)' conductor.cc:(.text+0x2f46): undefined reference to`rtc::GetStringFromJsonObject(Json::Value const&, std::string const&, std::string)' conductor.cc:(.text+0x2fa7): undefined reference tortc::GetIntFromJsonObject(Json::Value const&, std::string const&, int*)' conductor.cc:(.text+0x3004): undefined reference tortc::GetStringFromJsonObject(Json::Value const&, std::string const&, std::string*)' CMakeFiles/webrtcbridge_node.dir/src/peer_connection_client.cc.o:(.rodata._ZTI20PeerConnectionClient[_ZTI20PeerConnectionClient]+0x28): undefined reference to`typeinfo for rtc::MessageHandler'

Which could be these libraries? Or it is another problem?

Thanks again.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/aisouard/libwebrtc/issues/51#issuecomment-328040513, or mute the thread https://github.com/notifications/unsubscribe-auth/AAT1nr4MVNLNbq3orYWhKxYqKV6P5NPlks5sgPzOgaJpZM4PEeRn .

-- Alex. Gouaillard, PhD, PhD, MBA

President - CoSMo Software Consulting, Singapore

sg.linkedin.com/agouaillard

-

CharlieHollow commented 7 years ago

Thank you so much @agouaillard

I have added from webrtc/base/ as well:

agouaillard commented 7 years ago

If you use /base/ You re using an old version ;-)

Sent from my iPhone

On 8 Sep 2017, at 10:58 AM, CharlieHollow notifications@github.com wrote:

Closed #51.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

CharlieHollow commented 7 years ago

Okaay! Thanks again! :D

sampathkumar81293 commented 7 years ago

I have read this discussion and is helpful so far. @CharlieHollow Do you still have the updated CMakeList.txt If so . Can you share it ?

CharlieHollow commented 7 years ago

Hi @sampathkumar81293,

yes, I do. This is a simplify version of my CMakeLists.txt:

cmake_minimum_required(VERSION 3.3)
project(sample)

#add_compile_options(-std=c++11)

# Importing WebRTC Libraries
find_package(LibWebRTC REQUIRED)
include(${LIBWEBRTC_USE_FILE})

# Include JSONCPP libraries for JSON dependences
find_library(JSONCPP_LIBRARIES jsoncpp HINTS /usr/lib/x86_64-linux-gnu)

#Include header files
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${LIBWEBRTC_INCLUDE_DIRS})

set(JSON_INCLUDE_DIRS "/usr/include/jsoncpp")
include_directories(${JSON_INCLUDE_DIRS})

set(JSONCPP ~/libwebrtc/out/webrtc/src/build/linux/debian_jessie_amd64-sysroot/usr/lib/libjsoncpp.so)

# Find source files
file(GLOB SOURCES src/*.cpp src/*.cc)

add_executable(${PROJECT_NAME} ${SOURCES})

# Adding dependences
target_link_libraries(${PROJECT_NAME}
   ${LIBWEBRTC_LIBRARIES}
   ${JSONCPP_LIBRARIES}
   ${JSONCPP}
)

I don't know why, but I had to include two different json libraries to fix that problem.

By the way, what's your issue?

sampathkumar81293 commented 7 years ago

@CharlieHollow Thanks to you, this fixed my json/json.h errors :+1:

I was trying to build this [(https://github.com/llamerada-jp/webrtc-cpp-sample/blob/master/main.cpp)]

But my issue is that it ends up with this error main.cpp:(.text+0x1ff): undefined reference to rtc::MessageQueue::set_socketserver(rtc::SocketServer*) main.cpp:(.text+0x230): undefined reference to rtc::MessageQueue::set_socketserver(rtc::SocketServer*)

May be MessageQueue.cc / .h no longer has ser_sockerserver() method ?

Thanks again :)

CharlieHollow commented 7 years ago

Hi @sampathkumar81293,

if I remember well, "SocketServer" class is included in main.cc on WebRTC peer connection example, at the beginning of the .cc file.

Maybe you forgot to include it in your main.cpp file.

Try it and tell me if this fixes your problem.

You're welcome!

sampathkumar81293 commented 7 years ago

Hi @CharlieHollow It was completely my fault . The recent webrtc no longer uses set_socketserver() function.For eg This snippet CustomSocketServer socket_server(thread, &wnd); thread->set_socketserver(&socket_server);

is changed to

CustomSocketServer socket_server(&wnd); rtc::AutoSocketServerThread thread(&socket_server);

and other set_socketserver() usages has been omitted.

Thanks :)

coreTechie007 commented 5 years ago

Hi @CharlieHollow and @agouaillard

We are facing the same linker issues: undefined reference to typeinfo for rtc::PhysicalSocketServe undefined reference to rtc::GetStringFromJsonObject undefined reference to rtc::GetIntFromJsonObject undefined reference to typeinfo for webrtc::SetSessionDescriptionObserver undefined reference to typeinfo for webrtc::CreateSessionDescriptionObserver undefined reference to typeinfo for rtc::AdaptedVideoTrackSource undefined reference to typeinfo for rtc::MessageHandler

so for this we have added following source files to resolve these linker issue:

  1. physical_socket_server.cc + async_socket.cc
  2. json.cc
  3. jsep.cc
  4. adapted_video_track_source.cc
  5. message_handler.cc

After this project gets build successfully but when we try to run it it gives us an error:

Fatal error in: ../src/physical_socket_server.cc, line 1423
last system error: 11
Check failed: !processing_dispatchers_

Is this because of the mismatch sources ? but we used the sources from same webrtc cloned sources.

What is the stable latest webrtc source directory from where we can download ? and build webrtc library, so that we dont have to add above sources additionally.

Thanks in advance !

unnikrishnan-anil commented 4 years ago

@coreTechie007 were you able to solve the issue with jsep? or did you have to move to another version of webrtc?