#778531 libdebian-installer4-dev: Cannot include from C++

Package:
libdebian-installer4-dev
Source:
libdebian-installer
Description:
Library of common debian-installer functions
Submitter:
Askar Safin
Date:
2024-01-02 04:00:07 UTC
Severity:
normal
#778531#5
Date:
2015-02-16 11:42:46 UTC
From:
To:
I cannot build C++ programs using this library. G++ shows a lot of errors and warnings.

/usr/include/debian-installer/package.h:32:14: error: use of enum ‘di_package_dependency_type’ without previous declaration
 typedef enum di_package_dependency_type di_package_dependency_type;
              ^
/usr/include/debian-installer/package.h:32:67: error: invalid type in declaration before ‘;’ token
 typedef enum di_package_dependency_type di_package_dependency_type;
                                                                   ^
/usr/include/debian-installer/package.h:33:14: error: use of enum ‘di_package_priority’ without previous declaration
 typedef enum di_package_priority di_package_priority;
              ^
/usr/include/debian-installer/package.h:33:53: error: invalid type in declaration before ‘;’ token
 typedef enum di_package_priority di_package_priority;
                                                     ^
....

/usr/include/debian-installer/package.h: In function ‘di_package* di_package_alloc(di_packages_allocator*)’:
/usr/include/debian-installer/package.h:161:59: error: invalid conversion from ‘void*’ to ‘di_package*’ [-fpermissive]
   return di_mem_chunk_alloc0 (allocator->package_mem_chunk);
                                                           ^
/usr/include/debian-installer/package.h: In function ‘di_package_dependency* di_package_dependency_alloc(di_packages_allocator*)’:
/usr/include/debian-installer/package.h:166:70: error: invalid conversion from ‘void*’ to ‘di_package_dependency*’ [-fpermissive]
   return di_mem_chunk_alloc0 (allocator->package_dependency_mem_chunk);
                                                                      ^
Also, there is no extern "C"-trick in the headers.

#778531#10
Date:
2015-02-16 13:07:11 UTC
From:
To:
Askar Safin <safinaskar@mail.ru> (2015-02-16):

AFAICT from d-i's history, C++ has been kept out of it by design, so I
guess the issues you're having aren't entirely unexpected.

Mraw,
KiBi.

#778531#15
Date:
2015-08-04 21:01:07 UTC
From:
To:
Patch for source package libdebian-installer 0.99+deb8u1.

==
Askar Safin
http://vk.com/safinaskar

diff -Naur libdebian-installer-0.99+deb8u1/include/debian-installer/exec.h new/include/debian-installer/exec.h
--- libdebian-installer-0.99+deb8u1/include/debian-installer/exec.h	2014-11-05 01:19:08.000000000 +0000
+++ new/include/debian-installer/exec.h	2015-08-04 20:54:55.335590329 +0000
@@ -20,6 +20,11 @@
 #ifndef DEBIAN_INSTALLER__EXEC_H
 #define DEBIAN_INSTALLER__EXEC_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
 #include <debian-installer/types.h>

 #include <sys/types.h>
@@ -200,4 +205,9 @@
 }

 /** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff -Naur libdebian-installer-0.99+deb8u1/include/debian-installer/hash.h new/include/debian-installer/hash.h
--- libdebian-installer-0.99+deb8u1/include/debian-installer/hash.h	2014-11-05 01:19:08.000000000 +0000
+++ new/include/debian-installer/hash.h	2015-08-04 20:54:55.339590329 +0000
@@ -21,6 +21,11 @@
 #ifndef DEBIAN_INSTALLER__HASH_H
 #define DEBIAN_INSTALLER__HASH_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
 #include <debian-installer/types.h>

 /**
@@ -139,4 +144,9 @@
 di_ksize_t di_hash_table_size (di_hash_table *hash_table);

 /** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff -Naur libdebian-installer-0.99+deb8u1/include/debian-installer/list.h new/include/debian-installer/list.h
--- libdebian-installer-0.99+deb8u1/include/debian-installer/list.h	2014-11-05 01:19:08.000000000 +0000
+++ new/include/debian-installer/list.h	2015-08-04 20:54:55.339590329 +0000
@@ -20,6 +20,11 @@
 #ifndef DEBIAN_INSTALLER__LIST_H
 #define DEBIAN_INSTALLER__LIST_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
 #include <debian-installer/mem_chunk.h>

 typedef struct di_list di_list;
@@ -116,4 +121,9 @@
 void di_list_prepend_chunk (di_list *list, void *data, di_mem_chunk *mem_chunk) __attribute__ ((nonnull(1,3)));

 /** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff -Naur libdebian-installer-0.99+deb8u1/include/debian-installer/log.h new/include/debian-installer/log.h
--- libdebian-installer-0.99+deb8u1/include/debian-installer/log.h	2014-11-05 01:19:08.000000000 +0000
+++ new/include/debian-installer/log.h	2015-08-04 20:54:55.343590329 +0000
@@ -20,6 +20,11 @@
 #ifndef DEBIAN_INSTALLER__LOG_H
 #define DEBIAN_INSTALLER__LOG_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
 #include <stdarg.h>

 /**
@@ -104,4 +109,9 @@
   di_log_handler_syslog;

 /** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff -Naur libdebian-installer-0.99+deb8u1/include/debian-installer/mem.h new/include/debian-installer/mem.h
--- libdebian-installer-0.99+deb8u1/include/debian-installer/mem.h	2014-11-05 01:19:08.000000000 +0000
+++ new/include/debian-installer/mem.h	2015-08-04 20:54:55.351590330 +0000
@@ -21,6 +21,11 @@
 #ifndef DEBIAN_INSTALLER__MEM_H
 #define DEBIAN_INSTALLER__MEM_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
 #include <debian-installer/types.h>

 #include <stdio.h>
@@ -87,4 +92,9 @@
   ((struct_type *) di_realloc ((mem), sizeof (struct_type) * (n_structs)))

 /** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff -Naur libdebian-installer-0.99+deb8u1/include/debian-installer/mem_chunk.h new/include/debian-installer/mem_chunk.h
--- libdebian-installer-0.99+deb8u1/include/debian-installer/mem_chunk.h	2014-11-05 01:19:08.000000000 +0000
+++ new/include/debian-installer/mem_chunk.h	2015-08-04 20:54:55.355590330 +0000
@@ -21,6 +21,11 @@
 #ifndef DEBIAN_INSTALLER__MEM_CHUNK_H
 #define DEBIAN_INSTALLER__MEM_CHUNK_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
 #include <debian-installer/types.h>

 typedef struct di_mem_chunk di_mem_chunk;
@@ -37,4 +42,9 @@
 size_t di_mem_chunk_size (di_mem_chunk *mem_chunk);

 /** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff -Naur libdebian-installer-0.99+deb8u1/include/debian-installer/package.h new/include/debian-installer/package.h
--- libdebian-installer-0.99+deb8u1/include/debian-installer/package.h	2014-11-05 01:19:08.000000000 +0000
+++ new/include/debian-installer/package.h	2015-08-04 20:54:55.359590330 +0000
@@ -20,23 +20,16 @@
 #ifndef DEBIAN_INSTALLER__PACKAGE_H
 #define DEBIAN_INSTALLER__PACKAGE_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
 #include <debian-installer/mem.h>
 #include <debian-installer/parser.h>
 #include <debian-installer/slist.h>
 #include <debian-installer/string.h>

#778531#20
Date:
2015-08-05 03:01:53 UTC
From:
To:
Hi,

Askar Safin <safinaskar@mail.ru> (2015-08-05):

Thanks for the patch, but you haven't really told us about your usecase
with c++ in a d-i context.

Mraw,
KiBi.

#778531#25
Date:
2015-08-05 10:58:58 UTC
From:
To:
Any C library should allow including from C++. My usecase is following: I wrote my own analogue of debootstrap/cdebootstrap called asdebootstrap ("as" for Askar Safin, of course :)). I wrote it just because I like to experiment. It is written in shell, here is a source: http://paste.debian.net/289334 (some comments are in Russian). It depends on my util asdebootstrap-resolve, which performs actual dependencies resolving. asdebootstrap-resolve is written in C++, here is a source: http://paste.debian.net/289335 . asdebootstrap-resolve depends on libdebian-installer and on my library libsh: https://github.com/safinaskar/libsh. In particular, asdebootstrap-resolve depends on argument parser from libsh. This argument parser is written in C++14 and it heavily depends on C++11/C++14 features, including variadic templates. The parser is a header file arg.hpp and every file which includes it should be in C++14, too. So, asdebootstrap-resolve is C++14 and it includes libdebian-installer headers.
==
Askar Safin
http://vk.com/safinaskar