Qt + iperf3 = lconv has not been declared - c++

Sorry for my english.
I try to add iperf3 (like static link library) to my Qt project (Qt version 4.8.5, OpenSuse 13.1), and has several errors:
g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I../lperftest -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I../lperf/include -I. -I../lperftest -I. -o main.o ../lperftest/main.cpp
In file included from /usr/include/c++/4.8/x86_64-suse-linux/bits/c++locale.h:41:0,
from /usr/include/c++/4.8/bits/localefwd.h:40,
from /usr/include/c++/4.8/string:43,
from /usr/include/QtCore/qstring.h:54,
from /usr/include/QtCore/qobject.h:48,
from /usr/include/QtCore/QObject:1,
from ../lperftest/main.cpp:9:
/usr/include/c++/4.8/clocale:53:11: error: '::lconv' has not been declared
using ::lconv;
^
/usr/include/c++/4.8/clocale:54:11: error: '::setlocale' has not been declared
using ::setlocale;
^
/usr/include/c++/4.8/clocale:55:11: error: '::localeconv' has not been declared
using ::localeconv;
^
In file included from /usr/include/c++/4.8/bits/localefwd.h:40:0,
from /usr/include/c++/4.8/string:43,
from /usr/include/QtCore/qstring.h:54,
from /usr/include/QtCore/qobject.h:48,
from /usr/include/QtCore/QObject:1,
from ../lperftest/main.cpp:9:
/usr/include/c++/4.8/x86_64-suse-linux/bits/c++locale.h:52:23: error: 'uselocale' was not declared in this scope
extern "C" __typeof(uselocale) __uselocale;
^
/usr/include/c++/4.8/x86_64-suse-linux/bits/c++locale.h:52:45: error: invalid type in declaration before ';' token
extern "C" __typeof(uselocale) __uselocale;
^
/usr/include/c++/4.8/x86_64-suse-linux/bits/c++locale.h: In function 'int std::__convert_from_v(__locale_struct* const&, char*, int, const char*, ...)':
/usr/include/c++/4.8/x86_64-suse-linux/bits/c++locale.h:75:53: error: '__gnu_cxx::__uselocale' cannot be used as a function
__c_locale __old = __gnu_cxx::__uselocale(__cloc);
^
/usr/include/c++/4.8/x86_64-suse-linux/bits/c++locale.h:100:33: error: '__gnu_cxx::__uselocale' cannot be used as a function
__gnu_cxx::__uselocale(__old);
^
../lperftest/main.cpp: At global scope:
../lperftest/main.cpp:11:5: warning: unused parameter 'argc' [-Wunused-parameter]
int main(int argc, char *argv[])
^
../lperftest/main.cpp:11:5: warning: unused parameter 'argv' [-Wunused-parameter]
make: *** [main.o] Error 1
When i try to add iperf3 to the only C++ project all is good. This error exist only in Qt project. Is any idea?

I have the same problem with iperf3 and Qt. Basically it seems that you have to use similar compilation for iperf3 library and your project (both gcc or both g++).
Let us know how it goes. Or share your solution if already done.
-- edit --
or do the following for iperf_api.h
extern "C" {
#include <iperf_api.h>
}

Related

wchar.h: error: '__FILE' was not declared in this scope' error with gcc 5.2.0

I am having trouble compiling code
before it ever gets to the linker. Can anyone point me in the right
direction?
Here is the very simple code of source to reproduce this issue.
// CpxCryptoIfSimClientC.cpp //
#include <iostream>
// end
Compilation command line:
powerpc64-wrs-linux-g++ -c -o CpxCryptoIfSimClientC.o -m64 --sysroot=/proj/platform_cs/linux/deliveries/sdk_install/sysroots/ppc64e6500-wrs-linux -ggdb -O3 -Wextra -Wall -DPOWERPC64 -DLNX -D_GNU_SOURCE -Os -fno-unit-at-a-time -pedantic -Wall -Wno-long-long `xml2-config --cflags` -std=gnu++98 -DINLINE=__inline__ -I../inc CpxCryptoIfSimClientC.cpp
Output:
In file included from /proj/platform_cs/linux/deliveries/sdk_install/sysroots/ppc64e6500-wrs-linux/usr/include/c++/5.2.0/cwchar:44:0,
from /proj/platform_cs/linux/deliveries/sdk_install/sysroots/ppc64e6500-wrs-linux/usr/include/c++/5.2.0/bits/postypes.h:40,
from /proj/platform_cs/linux/deliveries/sdk_install/sysroots/ppc64e6500-wrs-linux/usr/include/c++/5.2.0/iosfwd:40,
from /proj/platform_cs/linux/deliveries/sdk_install/sysroots/ppc64e6500-wrs-linux/usr/include/c++/5.2.0/ios:38,
from /proj/platform_cs/linux/deliveriessdk_install/sysroots/ppc64e6500-wrs-linux/usr/include/c++/5.2.0/ostream:38,
from /proj/platform_cs/linux/deliveries/sdk_install/sysroots/ppc64e6500-wrs-linux/usr/include/c++/5.2.0/iostream:39,
from ../../TestHelperStrategy_ppc64_linux/SimTestHelper.h:29,
from ../CpxCryptoIfSimClientC.h:25,
from ../CpxCryptoIfSimClientC.cpp:20:
/proj/platform_cs/linux/deliveries/sdk_install/sysroots/ppc64e6500-wrs-linux/usr/include/wchar.h:582:8: error: '__FILE' does not name a type
extern __FILE *open_wmemstream (wchar_t **__bufloc, size_t *__sizeloc) __THROW;
/proj/platform_cs/linux/deliveries/epb/epb_epb2_v1.52/sdk_install/sysroots/ppc64e6500-wrs-linux/usr/include/wchar.h:589:19: error: '__FILE' was not declared in this scope extern int fwide (__FILE *__fp, int __mode) __THROW;
/proj/platform_cs/linux/deliveries/epb/epb_epb2_v1.52/sdk_install/sysroots/ppc64e6500-wrs-linux/usr/include/wchar.h:589:27: error: '__fp' was not declared in this scope extern int fwide (__FILE *__fp, int __mode) __THROW;
and many similiar errors which are "undeclared in this scope".
Here I am using gcc version 5.2.0 for powerpc64. Is there anything wrong with wchar.h or any other header file with this gcc version? or am I missing any flag here?

Unable to build wxWidgets on Cygwin - xlocale.h

I've been attempting to build wxWidgets 3.1.0 in Cygwin. I followed the process described in the install.txt, summarized below:
cd $WXWIN
mkdir build-debug
cd build-debug
../configure --enable-debug
make -j4
I have also tried a couple other flags for configure such as --with-X11, as suggest by this guide. The error I keep receiving, however, is the following:
/home/acohen8/wxWidgets-3.1.0/build-debug/bk-deps g++ -c -o basedll_strvararg.o -D__WXMSW__ -DWXBUILDING -I../src/regex -DwxUSE_GUI=0 -DWXMAKINGDLL_BASE -DwxUSE_BASE=1 -Wall -Wundef -Wunused-parameter -Wno-ctor-dtor-privacy -Woverloaded-virtual -D_FILE_OFFSET_BITS=64 -I/home/acohen8/wxWidgets-3.1.0/build-debug/lib/wx/include/msw-unicode-3.1 -I../include -g -O0 ../src/common/strvararg.cpp
In file included from ../src/common/string.cpp:39:0:
../include/wx/xlocale.h: In function ‘double wxStrtod_lA(const char*, char**, const wxXLocale&)’:
../include/wx/xlocale.h:243:54: error: ‘strtod_l’ was not declared in this scope
{ return wxCRT_Strtod_lA(c, endptr, loc.Get()); }
^
../include/wx/xlocale.h: In function ‘long int wxStrtol_lA(const char*, char**, int, const wxXLocale&)’:
../include/wx/xlocale.h:245:60: error: ‘strtol_l’ was not declared in this scope
{ return wxCRT_Strtol_lA(c, endptr, base, loc.Get()); }
^
../include/wx/xlocale.h: In function ‘long unsigned int wxStrtoul_lA(const char*, char**, int, const wxXLocale&)’:
../include/wx/xlocale.h:247:61: error: ‘strtoul_l’ was not declared in this scope
{ return wxCRT_Strtoul_lA(c, endptr, base, loc.Get()); }
^
../include/wx/xlocale.h: In function ‘double wxStrtod_l(const wchar_t*, wchar_t**, const wxXLocale&)’:
../include/wx/xlocale.h:301:58: error: ‘wcstod_l’ was not declared in this scope
{ return wxCRT_Strtod_lW(c, endptr, loc.Get()); }
^
../include/wx/xlocale.h: In function ‘long int wxStrtol_l(const wchar_t*, wchar_t**, int, const wxXLocale&)’:
../include/wx/xlocale.h:303:64: error: ‘wcstol_l’ was not declared in this scope
{ return wxCRT_Strtol_lW(c, endptr, base, loc.Get()); }
^
../include/wx/xlocale.h: In function ‘long unsigned int wxStrtoul_l(const wchar_t*, wchar_t**, int, const wxXLocale&)’:
../include/wx/xlocale.h:305:65: error: ‘wcstoul_l’ was not declared in this scope
{ return wxCRT_Strtoul_lW(c, endptr, base, loc.Get()); }
^
/home/acohen8/wxWidgets-3.1.0/build-debug/bk-deps g++ -c -o basedll_sysopt.o -D__WXMSW__ -DWXBUILDING -I../src/regex -DwxUSE_GUI=0 -DWXMAKINGDLL_BASE -DwxUSE_BASE=1 -Wall -Wundef -Wunused-parameter -Wno-ctor-dtor-privacy -Woverloaded-virtual -D_FILE_OFFSET_BITS=64 -I/home/acohen8/wxWidgets-3.1.0/build-debug/lib/wx/include/msw-unicode-3.1 -I../include -g -O0 ../src/common/sysopt.cpp
make: *** [Makefile:25366: basedll_string.o] Error 1
make: *** Waiting for unfinished jobs....
I would very much appreciate some suggestions on this!
This is most likely already fixed in wx's git master by this commit. But you can work around the problem by using configure --disable-xlocale.

Build of nixos.avrgcclibc fails on NixOS

I am trying to install avr-gcc-libc on NixOS, but run into a build error.
I try to install with the command
nix-env -iA nixos.avrgcclibc
The output this produces is very long and terminates with
g++ -c -DIN_GCC_FRONTEND -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -DHAVE_CONFIG_H -I. -Icp -I../../gcc -I../../gcc/cp -I../../gcc/../include -I../../gcc/../libcpp/include -I../../gcc/../libdecnumber -I../../gcc/../libdecnumber/dpd -I../libdecnumber -I../../gcc/../libbacktrace -o cp/except.o
-MT cp/except.o -MMD -MP -MF cp/.deps/except.TPo ../../gcc/cp/except.c
In file included from ./tm.h:18:0,
from ../../gcc/cp/except.c:27:
../../gcc/config/elfos.h:102:21: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
fprintf ((FILE), "%s"HOST_WIDE_INT_PRINT_UNSIGNED"\n",\
^
../../gcc/config/elfos.h:170:24: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n", \
^
In file included from ../../gcc/cp/except.c:1023:0:
cfns.gperf: In function 'const char* libc_name_p(const char*, unsigned int)':
cfns.gperf:101:1: error: 'const char* libc_name_p(const char*, unsigned int)' redeclared inline with 'gnu_inline' attribute
cfns.gperf:26:14: note: 'const char* libc_name_p(const char*, unsigned int)' previously declared here
cfns.gperf: At global scope:
cfns.gperf:26:14: warning: inline function 'const char* libc_name_p(const char*, unsigned int)' used but never defined
make[2]: *** [Makefile:1064: cp/except.o] Error 1
make[2]: Leaving directory '/tmp/nix-build-avr-gcc-libc.drv-0/gcc-5.3.0/obj-avr/gcc'
make[1]: *** [Makefile:4094: all-gcc] Error 2
make[1]: Leaving directory '/tmp/nix-build-avr-gcc-libc.drv-0/gcc-5.3.0/obj-avr'
make: *** [Makefile:852: all] Error 2
builder for ‘/nix/store/0ypaa4x9x0lsyygciasw9m1v4jswgm49-avr-gcc-libc.drv’ failed with exit code 2
error: build of ‘/nix/store/0ypaa4x9x0lsyygciasw9m1v4jswgm49-avr-gcc-libc.drv’ failed
What might the problem be? What can I do to get avr-gcc-libc to install successfully?

Undefined reference (but nm says the function exists) [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 5 years ago.
I have a library from a camera manufacturer, and in the demo code provided, a function called metadata_init() works fine, in my code though, I get an undefined reference error.
The make output from the demo code:
/opt/linaro-multilib-2013.09-gcc4.8/bin/arm-linux-gnueabihf-gcc -lm -g -L"/home/aro/Downloads" -o hicore demoS2.c -lpthread -lyuvlib -lrt
and thats it, the build succeeds fine, I will have a working ./hicore application in there.
My project is a little bit more complicated, and I compile using eclipse.
The console output is:
11:33:23 **** Build of configuration Camera-R4-Debug for project Camera ****
make all
Building file: ../src/Camera.cpp
Invoking: Cross G++ Compiler
arm-linux-gnueabihf-g++ -I/opt/Camerasdk/R4/include -I"/cameraBuilds/Wrapper/include" -I"/opt/ExternalLibraries/curl/Camera/R4/include" -I"/opt/ExternalLibraries/libxml2/Camera/R4/include" -I"/opt/ExternalLibraries/OpenCV24/Camera/R4/include" -I"/home/aro/cameraBuilds/Camera" -I/opt/InternalLibraries/include -I/opt/InternalLibraries/include_linux -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/Camera.d" -MT"src/Camera.o" -o "src/Camera.o" "../src/Camera.cpp"
../src/Camera.cpp: In function ‘int metadata_construct_http_message(char*, METADATA_HTTP_MESSAGE_TYPE, void*, int*)’:
../src/Camera.cpp:379:24: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
"</svg>\r\n";
^
../src/Camera.cpp: In function ‘int main()’:
../src/Camera.cpp:426:97: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
(void)metadata_init("stream.cgi", strlen("stream.cgi"), metadata_construct_http_message);
^
Finished building: ../src/Camera.cpp
Building file: ../src/CameraFrameGrabber.cpp
Invoking: Cross G++ Compiler
arm-linux-gnueabihf-g++ -I/opt/Camerasdk/R4/include -I"/cameraBuilds/Wrapper/include" -I"/opt/ExternalLibraries/curl/Camera/R4/include" -I"/opt/ExternalLibraries/libxml2/Camera/R4/include" -I"/opt/ExternalLibraries/OpenCV24/Camera/R4/include" -I"/home/aro/cameraBuilds/Camera" -I/opt/InternalLibraries/include -I/opt/InternalLibraries/include_linux -I/opt/InternalLibraries/ipslib/include -I/opt/InternalLibraries/ipsstream/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/CameraFrameGrabber.d" -MT"src/CameraFrameGrabber.o" -o "src/CameraFrameGrabber.o" "../src/CameraFrameGrabber.cpp"
Finished building: ../src/CameraFrameGrabber.cpp
Building file: ../src/CameraLogger.cpp
Invoking: Cross G++ Compiler
arm-linux-gnueabihf-g++ -I/opt/Camerasdk/R4/include -I"/home/aro/cameraBuilds/Wrapper/include" -I"/opt/ExternalLibraries/curl/Camera/R4/include" -I"/opt/ExternalLibraries/libxml2/Camera/R4/include" -I"/opt/ExternalLibraries/OpenCV24/Camera/R4/include" -I"/home/aro/cameraBuilds/Camera" -I/opt/InternalLibraries/include -I/opt/InternalLibraries/include_linux -I/opt/InternalLibraries/ipslib/include -I/opt/InternalLibraries/ipsstream/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/CameraLogger.d" -MT"src/CameraLogger.o" -o "src/CameraLogger.o" "../src/CameraLogger.cpp"
Finished building: ../src/CameraLogger.cpp
Building file: ../src/CameraParameter.cpp
Invoking: Cross G++ Compiler
arm-linux-gnueabihf-g++ -I/opt/Camerasdk/R4/include -I"/home/aro/cameraBuilds/Wrapper/include" -I"/opt/ExternalLibraries/curl/Camera/R4/include" -I"/opt/ExternalLibraries/libxml2/Camera/R4/include" -I"/opt/ExternalLibraries/OpenCV24/Camera/R4/include" -I"/home/aro/cameraBuilds/Camera" -I/opt/InternalLibraries/include -I/opt/InternalLibraries/include_linux -I/opt/InternalLibraries/ipslib/include -I/opt/InternalLibraries/ipsstream/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/CameraParameter.d" -MT"src/CameraParameter.o" -o "src/CameraParameter.o" "../src/CameraParameter.cpp"
Finished building: ../src/CameraParameter.cpp
Building target: Camera
Invoking: Cross G++ Linker
arm-linux-gnueabihf-g++ -L/opt/Camerasdk/R4/lib -L"/cameraBuilds/Wrapper/Camera-R4-Debug" -L"/opt/ExternalLibraries/curl/Camera/R4/lib" -L"/opt/ExternalLibraries/libxml2/Camera/R4/lib" -L"/opt/ExternalLibraries/OpenCV24/Camera/R4/lib" -L"/opt/DetectionModules/Camera/R4/lib" -L/home/aro/Downloads -o "Camera" ./src/Camera.o ./src/CameraFrameGrabber.o ./src/CameraLogger.o ./src/CameraParameter.o -lWrapper -lxml2 -lopencv_highgui -lopencv_imgproc -lopencv_core -lpthread -lyuvlib -lrt -llibjasper -llibjpeg -llibpng -llibtiff -lzlib -lcurl
./src/Camera.o: In function `main':
/home/aro/cameraBuilds/Camera/Camera-R4-Debug/../src/Camera.cpp:426: undefined reference to `metadata_init(char*, int, int (*)(char*, METADATA_HTTP_MESSAGE_TYPE, void*, int*))'
collect2: error: ld returned 1 exit status
make: *** [Camera] Error 1
11:33:24 Build Finished (took 1s.212ms)
The code itself is the very same thing, I just copied it over.
Metadata.h:
#ifndef _HIK_METADATA_H_
#define _HIK_METADATA_H_
const int max_http_body_len = 100 * 1024;
typedef enum
{
CMD_ADD_TYPE = 1,
CMD_OTHER,
} METADATA_CTRL_TYPE;
typedef struct
{
int length;
int fd;
METADATA_CTRL_TYPE cmd_type;
} METADATA_HEADER;
typedef struct
{
char option[128];
int share_socket;
} METADATA_ADD_CFG;
typedef enum
{
HTTP_HEADER_TYPE = 1,
HTTP_BODY_TYPE,
} METADATA_HTTP_MESSAGE_TYPE;
typedef struct
{
char boundary[64];
char http_content_type[64];
char multipart_content_type[64];
} METADATA_MULTIPART_TYPE;
typedef int (*p_metadata_construct_http_msg_callback_f)(char *p_option, METADATA_HTTP_MESSAGE_TYPE cmd_type, void *p_data, int *p_data_len);
int metadata_init(char *p_metadata_url, int url_len, p_metadata_construct_http_msg_callback_f p_callback_f);
#endif
In Camera.cpp:
#include "Metadata.h"
int metadata_construct_http_message(char *p_option, METADATA_HTTP_MESSAGE_TYPE cmd_type, void *p_data, int *p_data_len)
{
// Removed for SO
return 0;
}
int main()
{
(void)metadata_init("stream.cgi", strlen("stream.cgi"), metadata_construct_http_message);
...
}
What causes this, and how can I debug this issue to narrow down how to fix it?
It think the problem could be that metadata_init is a C function, but you use it from a C++ code.
In case of this, extern "C" must be used in the header file, like this:
#ifdef __cplusplus
extern "C" {
#endif
// embed the whole contents of the header file here, I just put the function here for brevity
int metadata_init(char *p_metadata_url, int url_len, p_metadata_construct_http_msg_callback_f p_callback_f);
#ifdef __cplusplus
}
#endif
It is because of name mangling rules. Names are mangled differently in C and C++. With extern "C", you tell the compiler that the names inside should be used with "C" mangling.
C++ has to do a complex name mangling compared to C, because it has to embed almost all signature information to a name (all parameters type), while in C, the mangled name usually is the same as the function name, or there is a _ prepended.

C++ compile issue

meme#ubuntu:~/Data$ g++ UDPEchoServer.cpp PracticalSocket.cpp -o udpskserv -lsocket -lnsl -mt
I trying to compile at my compiler ubuntu and i receive this error
cc1plus: error: unrecognized command line option ‘-mt’
May i ask what is -mt , i try google but can't find any information.
If I try omit the -mt parameter i get this error
PracticalSocket.cpp: In constructor ‘SocketException::SocketException(const string&, bool)’:
PracticalSocket.cpp:33:38: error: ‘strerror’ was not declared in this scope
PracticalSocket.cpp: In function ‘void fillAddr(const string&, short unsigned int, sockaddr_in&)’:
PracticalSocket.cpp:47:32: error: ‘memset’ was not declared in this scope
PracticalSocket.cpp: In member function ‘void Socket::setLocalPort(short unsigned int)’:
PracticalSocket.cpp:119:42: error: ‘memset’ was not declared in this scope
PracticalSocket.cpp: In static member function ‘static short unsigned int Socket::resolveService(const string&, const string&)’:
PracticalSocket.cpp:153:32: error: ‘atoi’ was not declared in this scope
PracticalSocket.cpp: In member function ‘void UDPSocket::disconnect()’:
PracticalSocket.cpp:291:40: error: ‘memset’ was not declared in this scope
Both std::memset and std::strerror are declared in the <cstring> header, you need to #include that one.
And GCC does not have a -mt option.