语言

Menu
Sites
Language
Linker error with clock_gettime when using iostream

Hello,

    I am currently in the process of developping a Tizen Native Service which depends on a portable homemade C++ library. This library includes iostream in some of it's debug capabilities.

   However, I am unable to build even the smallest program in Tizen Studio which includes both thread and iostream:

   Take this sample program:

#include <tizen.h>
#include <service_app.h>
#include "service.h"
#include <iostream>

bool service_app_create(void *data)
{
    // Todo: add your code here.
    return true;
}

void service_app_terminate(void *data)
{
    // Todo: add your code here.
    return;
}

void service_app_control(app_control_h app_control, void *data)
{
    // Todo: add your code here.
    return;
}

int main(int argc, char* argv[])
{
    char ad[50] = {0,};
    service_app_lifecycle_callback_s event_callback;
	app_event_handler_h handlers[5] = {NULL, };

	event_callback.create = service_app_create;
	event_callback.terminate = service_app_terminate;
	event_callback.app_control = service_app_control;

	return service_app_main(argc, argv, &event_callback, ad);
}

When using the wearable 2.3.2 arm GCC-4.9 tool chain, I get the following error when the linker is invoked:

arm-linux-gnueabi-g++ -o service src/service.o   -L"../lib" -Xlinker --as-needed  -pie -lpthread --sysroot="/home/bruno/tizen-studio/tools/smart-build-interface/../../platforms/tizen-2.3.2/wearable/rootstraps/wearable-2.3.2-device.core" -Xlinker --version-script="../.exportMap" -L"/home/bruno/tizen-studio/tools/smart-build-interface/../../platforms/tizen-2.3.2/wearable/rootstraps/wearable-2.3.2-device.core/usr/lib" -lBrokenLocale -lanl -lappcore-agent -lappcore-watch -lbadge -lbase-utils-i18n -lbundle -lcairo -lcapi-appfw-alarm -lcapi-appfw-app-common -lcapi-appfw-app-control -lcapi-appfw-application -lcapi-appfw-app-manager -lcapi-appfw-package-manager -lcapi-appfw-preference -lcapi-appfw-widget-application -lcapi-base-common -lcapi-content-media-content -lcapi-content-mime-type -lcapi-data-control -lcapi-location-manager -lcapi-maps-service -lcapi-media-audio-io -lcapi-media-camera -lcapi-media-codec -lcapi-media-image-util -lcapi-media-metadata-extractor -lcapi-media-player -lcapi-media-radio -lcapi-media-recorder -lcapi-media-sound-manager -lcapi-media-tone-player -lcapi-media-tool -lcapi-media-wav-player -lcapi-message-port -lcapi-messaging-messages -lcapi-network-bluetooth -lcapi-network-connection -lcapi-network-nfc -lcapi-network-smartcard -lcapi-network-wifi -lcapi-system-device -lcapi-system-info -lcapi-system-media-key -lcapi-system-runtime-info -lcapi-system-sensor -lcapi-system-system-settings -lcapi-telephony -lcapi-ui-efl-util -lcidn -lcore-context-manager -lcrypto -lcrypt -lc -lcurl -ldlog -ldl -lecore_con -lecore_evas -lecore_fb -lecore_file -lecore_imf_evas -lecore_imf -lecore_input_evas -lecore_input -lecore_ipc -lecore -lecore_x -ledbus -ledje -leet -lefl-extension -lefreet_mime -lefreet -lefreet_trash -leina -leio -lelementary -lembryo -lethumb_client -lethumb -levas -lewebkit2 -lexif -lfontconfig -lfreetype -lgio-2.0 -lglib-2.0 -lgmodule-2.0 -lgobject-2.0 -lgthread-2.0 -ljson-glib-1.0 -lkey-manager-client -lminizip -lm -lnotification -lnsl -lnss_compat -lnss_dns -lnss_files -lnss_hesiod -lnss_nisplus -lnss_nis -loauth -lopenal -lprivilege-info -lpthread -lpush -lresolv -lrt -lsqlite3 -lssl -lstorage -lstt -ltbm -lthread_db -lttrace -ltts -lutil -lwidget_service -lwidget_viewer_evas -lxml2 -lz -Xlinker -rpath="/opt/usr/apps/org.example.service/lib" -Werror-implicit-function-declaration/home/bruno/tizen-studio/tools/arm-linux-gnueabi-gcc-4.9/bin/../lib/gcc/arm-linux-gnueabi/4.9.2/../../../../arm-linux-gnueabi/lib/libstdc++.so: undefined reference to `clock_gettime@GLIBC_2.17'

This issue was encountered with Tizen Studio 1.2 with the wear-2.3.2 package. I cannot find which library is supposed to provide the clock_gettime symbol, but it does not seem to be included in the system libs.

This same program works without any issue when using the gcc 4.6 tool chain, but I find it strange that I cannot use the latest version of the libs for my project.

 

响应

4 回复
Shaswati Saha

The reason is toolchain packages for GCC 4.9 is not installed for Wearable version 2.3.2. If you try the same thing with Mobile 2.4 version with GCC 4.9 then you'll find it working. Please have a look into the images below:

In Wearable 2.3.2 :

 

In Mobile 2.4 :

Raimundo Martins

I don't know if this solved the OP's problem (I don't think so), but it doesn't solve it for me.

GCC 4.9 can't be used with 2.3.2 because librt is in the platforms/rootstrap and libstdc++.so is in tools/*gcc-4.9

$ readelf -Ws tizen-studio/platforms/tizen-2.3.2/wearable/rootstraps/wearable-2.3.2-device.core/lib/librt.so.1 | grep clock_gettime
  74: 000036fc    96 FUNC    GLOBAL DEFAULT   13 clock_gettime@@GLIBC_2.4
$ readelf -Ws tizen-studio/tools/arm-linux-gnueabi-gcc-4.9/arm-linux-gnueabi/lib/libstdc++.so | grep clock_gettime
  439: 00000000     0 FUNC    GLOBAL DEFAULT  UND clock_gettime@GLIBC_2.17 (38)
  9042: 00000000     0 FUNC    GLOBAL DEFAULT  UND clock_gettime@@GLIBC_2.17

This is a sad state of affairs, because I need to develop for 2.3.2 (Gear S3) but gcc 4.6 is too old (GCC 4 is too old...). I'd like to develop using C++11 and also use the Catch library, but I get "error: no type named 'underlying_type' in namespace 'std'" because 4.6 doesn't have it.

I'm new to the cross-compilation scene, but I wonder if this isn't just some libs being out of place (like libstdc++ not being in rootstraps). It doesn't feel like I shouldn't be able to mix-and-match platforms and compilers at will because of library versions.

Maarten van Sambeek

Hi,

After a lot of tries, I figured out that if you link the libstdc++ statically, you don't have this problem. I don't know if this fixes it for you, but I was able to build when I added the linker flag -static-libstdc++.

Project > Properties...

C/C++ Build > Settings > C++ Compiler > Miscellaneous > Linker flags

​Hope this helps!

 

Shaswati Saha

Hi Bruno Falardeau,

What's the status right now? Did you solve the problem?