How can I compile the example code using g++?

Asked by Kent Lai on 2014-05-07

Hello,

I want to use this library in my c++ program.

I followed steps to compile the example code in tutorial.

$gcc -o simple_rohc_program.exe $(pkg-config rohc --cflags) simple_rohc_program.c $(pkg-config rohc --libs) -I ../

The above command is work for gcc, but when I use g++ with the same parameters to compile the example code, I get following error messages:

/tmp/ccOVvx9H.o: In function `main':
simple_rohc_program.c:(.text+0x5a): undefined reference to `rohc_alloc_compressor(int, int, int, int)'
simple_rohc_program.c:(.text+0xb4): undefined reference to `rohc_comp_set_random_cb(rohc_comp*, int (*)(rohc_comp const*, void*), void*)'
simple_rohc_program.c:(.text+0x108): undefined reference to `rohc_activate_profile(rohc_comp*, int)'
simple_rohc_program.c:(.text+0x11f): undefined reference to `rohc_activate_profile(rohc_comp*, int)'
simple_rohc_program.c:(.text+0x2ff): undefined reference to `rohc_compress2(rohc_comp*, unsigned char const*, unsigned int, unsigned char*, unsigned int, unsigned int*)'
simple_rohc_program.c:(.text+0x3f8): undefined reference to `rohc_free_compressor(rohc_comp*)'
simple_rohc_program.c:(.text+0x41a): undefined reference to `rohc_free_compressor(rohc_comp*)'
collect2: ld returned 1 exit status

How can I fix this problem?

Question information

Language:
English Edit question
Status:
Solved
For:
rohc Edit question
Assignee:
No assignee Edit question
Solved by:
Kent Lai
Solved:
2014-05-08
Last query:
2014-05-08
Last reply:
2014-05-07

Hello,

What is the output of the following commands:
 $ pkg-config rohc --modversion
 $ pkg-config rohc --cflags
 $ pkg-config rohc --libs

Regards,
Didier

Kent Lai (s100321003) said : #2

$ pkg-config rohc --modversion
1.6.1

$ pkg-config rohc --cflags

$ pkg-config rohc --libs
-lrohc_decomp -lrohc_comp -lrohc_common

The output of the second command is a blank line.

Regards,
Kent

Re,

The problem is related to the build of a C++ program with g++ with the ROHC library written in C. The 1.6.1 version of the ROHC library is not ready for this.

Please apply the following patch on 1.6.1, re-build and install, then try again to build the example with g++.

Didier

=== modified file 'src/common/rohc.h'
--- src/common/rohc.h 2013-06-08 20:43:28 +0000
+++ src/common/rohc.h 2014-05-07 18:36:14 +0000
@@ -25,6 +25,11 @@
 #ifndef ROHC_H
 #define ROHC_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
 /**
  * \mainpage
  *
@@ -339,5 +344,9 @@ void ROHC_EXPORT crc_init_table(unsigned

 #undef ROHC_EXPORT /* do not pollute outside this header */

+#ifdef __cplusplus
+}
+#endif
+
 #endif

=== modified file 'src/common/rohc_packets.h'
--- src/common/rohc_packets.h 2012-09-08 10:58:03 +0000
+++ src/common/rohc_packets.h 2014-05-07 18:37:16 +0000
@@ -23,6 +23,11 @@
 #ifndef ROHC_PACKETS_H
 #define ROHC_PACKETS_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+

 /** Macro that handles DLL export declarations gracefully */
 #ifdef DLL_EXPORT /* passed by autotools on command line */
@@ -100,5 +105,9 @@ const char * ROHC_EXPORT rohc_get_ext_de

 #undef ROHC_EXPORT /* do not pollute outside this header */

+#ifdef __cplusplus
+}
+#endif
+
 #endif

=== modified file 'src/common/rohc_traces.h'
--- src/common/rohc_traces.h 2013-08-20 18:26:16 +0000
+++ src/common/rohc_traces.h 2014-05-07 18:36:26 +0000
@@ -25,6 +25,10 @@
 #ifndef ROHC_TRACES_H
 #define ROHC_TRACES_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif

 /**
  * @brief A general profile number used for traces not related to a specific
@@ -88,6 +92,9 @@ typedef void (*rohc_trace_callback_t) (c
  __attribute__((format(printf, 4, 5)));
 #endif

+#ifdef __cplusplus
+}
+#endif

 #endif

=== modified file 'src/comp/rohc_comp.h'
--- src/comp/rohc_comp.h 2013-05-20 15:33:18 +0000
+++ src/comp/rohc_comp.h 2014-05-07 18:36:35 +0000
@@ -25,6 +25,11 @@
 #ifndef COMP_H
 #define COMP_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
 #include "rohc.h"
 #include "rohc_packets.h"
 #include "rohc_traces.h"
@@ -438,5 +443,9 @@ const char * ROHC_EXPORT rohc_comp_get_s

 #undef ROHC_EXPORT /* do not pollute outside this header */

+#ifdef __cplusplus
+}
+#endif
+
 #endif

=== modified file 'src/decomp/rohc_decomp.h'
--- src/decomp/rohc_decomp.h 2013-06-08 20:30:03 +0000
+++ src/decomp/rohc_decomp.h 2014-05-07 18:36:40 +0000
@@ -26,6 +26,11 @@
 #ifndef DECOMP_H
 #define DECOMP_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
 #include "rohc.h"
 #include "rohc_comp.h"

@@ -188,5 +193,9 @@ bool ROHC_EXPORT rohc_decomp_set_traces_

 #undef ROHC_EXPORT /* do not pollute outside this header */

+#ifdef __cplusplus
+}
+#endif
+
 #endif

Kent Lai (s100321003) said : #4

Thanks for your quick answer.
This problem is solved.

Regards,
Kent

The change was committed in the 1.6.x branch. It will be part of the next stable 1.6.2 release.