Hi

I tested the writing of libeweather plugin where part of the code is written in c++.
I found 2 small problems when building the code with gcc on Linux.
Attached patch fix both of the problems for me and I got my plugin working.
I also tested that it did not break the existing test plugin from the libeweather.

1) First problem came out when I included the "EWeather.h" to c++ file.

In file included from /usr/local/include/EWeather_Plugins.h:4,
from W1DeviceManagerController.hh:14,
from W1DeviceManagerController.cc:15:
/usr/local/include/EWeather.h:9: error: use of enum ‘EWeather_Type’ without previous declaration /usr/local/include/EWeather.h:9: error: invalid type in declaration before ‘;’ token /usr/local/include/EWeather.h:10: error: use of enum ‘EWeather_Temp’ without previous declaration /usr/local/include/EWeather.h:10: error: invalid type in declaration before ‘;’ token /usr/local/include/EWeather.h:14: error: using typedef-name ‘EWeather_Type’ after ‘enum’ /usr/local/include/EWeather.h:9: error: ‘EWeather_Type’ has a previous declaration here /usr/local/include/EWeather.h:35: error: using typedef-name ‘EWeather_Temp’ after ‘enum’ /usr/local/include/EWeather.h:10: error: ‘EWeather_Temp’ has a previous declaration here

This problem appeared because in EWeather.h there were these 2 typedef enum lines before the enums itself were defined. The fix for this one was simply to move these lines couple of lines lower after the enums were introduced.
typedef enum EWeather_Type EWeather_Type;
typedef enum EWeather_Temp EWeather_Temp;

2) Second problem came from the linker. It failed to find the functions when tried to link them from the c++ code. Fix for this is to put the public API function definitions in EWeather.h and EWeather_Plugins.h to following kind of block.

#ifdef __cplusplus
extern"C" {
#endif
...
#ifdef __cplusplus
}
#endif

Signed-off-by: Mika Laitio <lam...@pilppa.org>

Mika
Index: src/lib/EWeather.h
===================================================================
--- src/lib/EWeather.h  (revision 57540)
+++ src/lib/EWeather.h  (working copy)
@@ -3,12 +3,13 @@
 
 #include <Eina.h>
 
+#ifdef __cplusplus
+       extern"C" {
+#endif
+
 typedef struct EWeather EWeather;
 typedef struct EWeather_Data EWeather_Data;
 
-typedef enum EWeather_Type EWeather_Type;
-typedef enum EWeather_Temp EWeather_Temp;
-
 typedef void (*Update_Cb) (void *data, EWeather *eweather);
 
 enum EWeather_Type
@@ -38,6 +39,9 @@
    EWEATHER_TEMP_CELCIUS
 };
 
+typedef enum EWeather_Type EWeather_Type;
+typedef enum EWeather_Temp EWeather_Temp;
+
 EAPI   Eina_Array *    eweather_plugins_list_get(EWeather *eweather);
 EAPI   Eina_Module *   eweather_plugin_search(EWeather *eweather, const char 
*name);
 EAPI   const char *    eweather_plugin_name_get(EWeather *eweather, int i);
@@ -76,4 +80,8 @@
 
 EAPI   int             eweather_utils_celcius_get(int farenheit);
 
+#ifdef __cplusplus
+       }
 #endif
+
+#endif
Index: src/lib/EWeather_Plugins.h
===================================================================
--- src/lib/EWeather_Plugins.h  (revision 57540)
+++ src/lib/EWeather_Plugins.h  (working copy)
@@ -6,6 +6,10 @@
 #include <string.h>
 #include <stdio.h>
 
+#ifdef __cplusplus
+       extern"C" {
+#endif
+
 typedef struct EWeather_Plugin EWeather_Plugin;
 typedef void (*Plugin_Init) (EWeather *eweather);
 typedef void (*Plugin_Shutdown) (EWeather *eweather);
@@ -69,4 +73,8 @@
 EAPI void eweather_plugin_update(EWeather *eweather);
 void eweather_plugin_shutdown(EWeather *eweather);
 
+#ifdef __cplusplus
+       }
 #endif
+
+#endif
------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to