Dear Developers & friends,
I installed the libzdb on my systems from the sources and the compilation and installation was finished successfull, later I can see the includes into my /usr/local/include/zdb folder, but when I put the header : #include <zdb/zdb.h> into my C++ project, it launch an exception on building time.
**** Build of configuration Debug for project SerialTest2 ****
make all Building file: ../src/SerialTest2.cpp Invoking: GCC C++ Compiler g++ -I/usr/local/include/zdb -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/SerialTest2.d" -MT"src/SerialTest2.d" -o"src/SerialTest2.o" "../src/SerialTest2.cpp" In file included from /usr/local/include/zdb/zdb.h:33, from ../src/SerialTest2.cpp:19: /usr/local/include/zdb/URL.h:55: *error: conflicting declaration ‘typedef struct URL_T* URL_T’* /usr/local/include/zdb/URL.h:55: *error: ‘struct URL_T’ has a previous declaration as ‘struct URL_T’* *...* * * * * Somebody has an idea that what's happen? Thanks in advance Toni
On Oct 26, 2011, at 5:56 PM, Antonio Castellon - RAC wrote:
**** Build of configuration Debug for project SerialTest2 ****
make all Building file: ../src/SerialTest2.cpp Invoking: GCC C++ Compiler g++ -I/usr/local/include/zdb -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/SerialTest2.d" -MT"src/SerialTest2.d" -o"src/SerialTest2.o" "../src/SerialTest2.cpp" In file included from /usr/local/include/zdb/zdb.h:33, from ../src/SerialTest2.cpp:19: /usr/local/include/zdb/URL.h:55: error: conflicting declaration ‘typedef struct URL_T* URL_T’ /usr/local/include/zdb/URL.h:55: error: ‘struct URL_T’ has a previous declaration as ‘struct URL_T’ ...
Somebody has an idea that what's happen?
Yes, I suspect the reason is that the interfaces of libzdb does not use the "extern C" as in
#ifdef __cplusplus extern "C" { #endif
<libzdb header declarations>
#ifdef __cplusplus } #endif
It was omitted more as a "fashion" statement than for practical purposes.
On Oct 26, 2011, at 5:56 PM, Antonio Castellon - RAC wrote:
Interesting. This has nothing to do with extern "C" which I mentioned earlier, though extern "C" should be added to libzdb headers if to be used from C++.
Out of curiosity I tested this and got the same error:
/usr/local/include/zdb/URL.h:55: error: conflicting declaration ‘typedef struct URL_T* URL_T’ /usr/local/include/zdb/URL.h:55: error: ‘struct URL_T’ has a previous declaration as ‘struct URL_T’
It seems that the problem has to do with forward declaration and namespaces in C vs C++. In C, structs are in a separate namespace so it is perfectly legal to forward declare and typedef a struct to a type of the same name. That is;
typedef struct URL_T *URL_T;
But this does not work in C++ (as far as I understand, I'm no C++ guy though). In C++ a struct is (basically) the same as a class, so typedef *URL_T is in the same namespace as struct URL_T, hence the curious compiler error "‘struct URL_T’ has a previous declaration as ‘struct URL_T’". The "workaround" is simple; just give the two types different names. For instance lowercase the struct name:
typedef struct url_t *URL_T;
Since we use this typedef forward declaration idiom to declare all API objects in libzdb you would have to modify all the 5-6 API header files and corresponding source code where the type is declared, if you still want to use libzdb from C++. It is a question of modifying only 5 lines or so. Though I'm not inclined to do the change in the repository since this just demonstrated how C is superior to C++ (Obviously I'm a C guy :)
Best
Dear Jan,
First of all, thanks for your answers. I don't want to evaluate if C is better than C++, on my particular case, I have need to integrate the libzdb into a framework of C++. Perhaps If you are interested (and if it is possible), I could modify the headers of this API according to C++ compatibility and send to the packet in order that you include (not substitute) this new header files as a complement for future users that has the same problem than me. Very thanks for your support, Best regards Toni
On Thu, Oct 27, 2011 at 03:10, Jan-Henrik Haukeland hauk@tildeslash.comwrote:
On Oct 26, 2011, at 5:56 PM, Antonio Castellon - RAC wrote:
Interesting. This has nothing to do with extern "C" which I mentioned earlier, though extern "C" should be added to libzdb headers if to be used from C++.
Out of curiosity I tested this and got the same error:
/usr/local/include/zdb/URL.h:55: error: conflicting declaration ‘typedef
struct URL_T* URL_T’
/usr/local/include/zdb/URL.h:55: error: ‘struct URL_T’ has a previous
declaration as ‘struct URL_T’
It seems that the problem has to do with forward declaration and namespaces in C vs C++. In C, structs are in a separate namespace so it is perfectly legal to forward declare and typedef a struct to a type of the same name. That is;
typedef struct URL_T *URL_T;
But this does not work in C++ (as far as I understand, I'm no C++ guy though). In C++ a struct is (basically) the same as a class, so typedef *URL_T is in the same namespace as struct URL_T, hence the curious compiler error "‘struct URL_T’ has a previous declaration as ‘struct URL_T’". The "workaround" is simple; just give the two types different names. For instance lowercase the struct name:
typedef struct url_t *URL_T;
Since we use this typedef forward declaration idiom to declare all API objects in libzdb you would have to modify all the 5-6 API header files and corresponding source code where the type is declared, if you still want to use libzdb from C++. It is a question of modifying only 5 lines or so. Though I'm not inclined to do the change in the repository since this just demonstrated how C is superior to C++ (Obviously I'm a C guy :)
Best
-- To unsubscribe: http://www.tildeslash.com/mailman/listinfo/libzdb-general
Wow, I spend too much time to refactoring the code, but it not compile fine. :-( it's not easy to modify the problem with the typedef structs definition...or perhaps i'm wrong and it is more easy than I found.... could you check if it is more complicated? if not, I will forced to search to another library to be used on my project :-(
thanks for all toni
On Thu, Oct 27, 2011 at 06:25, Antonio Castellon - RAC < antonio.castellon.rac@gmail.com> wrote:
Dear Jan,
First of all, thanks for your answers. I don't want to evaluate if C is better than C++, on my particular case, I have need to integrate the libzdb into a framework of C++. Perhaps If you are interested (and if it is possible), I could modify the headers of this API according to C++ compatibility and send to the packet in order that you include (not substitute) this new header files as a complement for future users that has the same problem than me. Very thanks for your support, Best regards Toni
On Thu, Oct 27, 2011 at 03:10, Jan-Henrik Haukeland hauk@tildeslash.comwrote:
On Oct 26, 2011, at 5:56 PM, Antonio Castellon - RAC wrote:
Interesting. This has nothing to do with extern "C" which I mentioned earlier, though extern "C" should be added to libzdb headers if to be used from C++.
Out of curiosity I tested this and got the same error:
/usr/local/include/zdb/URL.h:55: error: conflicting declaration
‘typedef struct URL_T* URL_T’
/usr/local/include/zdb/URL.h:55: error: ‘struct URL_T’ has a previous
declaration as ‘struct URL_T’
It seems that the problem has to do with forward declaration and namespaces in C vs C++. In C, structs are in a separate namespace so it is perfectly legal to forward declare and typedef a struct to a type of the same name. That is;
typedef struct URL_T *URL_T;
But this does not work in C++ (as far as I understand, I'm no C++ guy though). In C++ a struct is (basically) the same as a class, so typedef *URL_T is in the same namespace as struct URL_T, hence the curious compiler error "‘struct URL_T’ has a previous declaration as ‘struct URL_T’". The "workaround" is simple; just give the two types different names. For instance lowercase the struct name:
typedef struct url_t *URL_T;
Since we use this typedef forward declaration idiom to declare all API objects in libzdb you would have to modify all the 5-6 API header files and corresponding source code where the type is declared, if you still want to use libzdb from C++. It is a question of modifying only 5 lines or so. Though I'm not inclined to do the change in the repository since this just demonstrated how C is superior to C++ (Obviously I'm a C guy :)
Best
-- To unsubscribe: http://www.tildeslash.com/mailman/listinfo/libzdb-general
Hi Toni
I have modified the API as I described and tested that I can compile test/select.c with g++ (on OS X). I used
g++ -o select -L../.libs/ -lzdb -I../zdb select.c
You can download the C++ compatible version from http://www.tildeslash.com/libzdb/dist/libzdb-2.10.tar.gz
Please let me know if it works in your project. If it does, I'll keep the changes so libzdb can be used from C++ in the future.
Best regards
On Oct 27, 2011, at 10:51 AM, Antonio Castellon - RAC wrote:
Wow, I spend too much time to refactoring the code, but it not compile fine. :-( it's not easy to modify the problem with the typedef structs definition...or perhaps i'm wrong and it is more easy than I found.... could you check if it is more complicated? if not, I will forced to search to another library to be used on my project :-(
thanks for all toni
On Thu, Oct 27, 2011 at 06:25, Antonio Castellon - RAC antonio.castellon.rac@gmail.com wrote: Dear Jan,
First of all, thanks for your answers. I don't want to evaluate if C is better than C++, on my particular case, I have need to integrate the libzdb into a framework of C++. Perhaps If you are interested (and if it is possible), I could modify the headers of this API according to C++ compatibility and send to the packet in order that you include (not substitute) this new header files as a complement for future users that has the same problem than me. Very thanks for your support, Best regards Toni
Hi again
I have added the C++ modifications to the repository so they will be part of the next release. Since the modifications where non-intrusive and simple (http://code.google.com/p/libzdb/source/detail?r=448#) there was no reason not to allow C++ or Obj-C(++) projects from using libzdb. Could you do me a favor, download and test libzdb, http://www.tildeslash.com/libzdb/dist/libzdb-2.10.tar.gz and let me know if it now works in your C++ project?
Ps. People that use libzdb from C need not worry as the API has not changed and no code changes are required on your part.
On Oct 27, 2011, at 6:56 PM, Jan-Henrik Haukeland wrote:
Hi Toni
I have modified the API as I described and tested that I can compile test/select.c with g++ (on OS X). I used
g++ -o select -L../.libs/ -lzdb -I../zdb select.c
You can download the C++ compatible version from http://www.tildeslash.com/libzdb/dist/libzdb-2.10.tar.gz
Please let me know if it works in your project. If it does, I'll keep the changes so libzdb can be used from C++ in the future.
Best regards
On Oct 27, 2011, at 10:51 AM, Antonio Castellon - RAC wrote:
Wow, I spend too much time to refactoring the code, but it not compile fine. :-( it's not easy to modify the problem with the typedef structs definition...or perhaps i'm wrong and it is more easy than I found.... could you check if it is more complicated? if not, I will forced to search to another library to be used on my project :-(
thanks for all toni
On Thu, Oct 27, 2011 at 06:25, Antonio Castellon - RAC antonio.castellon.rac@gmail.com wrote: Dear Jan,
First of all, thanks for your answers. I don't want to evaluate if C is better than C++, on my particular case, I have need to integrate the libzdb into a framework of C++. Perhaps If you are interested (and if it is possible), I could modify the headers of this API according to C++ compatibility and send to the packet in order that you include (not substitute) this new header files as a complement for future users that has the same problem than me. Very thanks for your support, Best regards Toni
Thanks Jan, I'm not a pure C ;-) Now it's compile on C++ project sucessfully. Thanks again for your support. Toni.
On Fri, Oct 28, 2011 at 01:13, Jan-Henrik Haukeland hauk@tildeslash.comwrote:
Hi again
I have added the C++ modifications to the repository so they will be part of the next release. Since the modifications where non-intrusive and simple (http://code.google.com/p/libzdb/source/detail?r=448#) there was no reason not to allow C++ or Obj-C(++) projects from using libzdb. Could you do me a favor, download and test libzdb, http://www.tildeslash.com/libzdb/dist/libzdb-2.10.tar.gz and let me know if it now works in your C++ project?
Ps. People that use libzdb from C need not worry as the API has not changed and no code changes are required on your part.
On Oct 27, 2011, at 6:56 PM, Jan-Henrik Haukeland wrote:
Hi Toni
I have modified the API as I described and tested that I can compile
test/select.c with g++ (on OS X). I used
g++ -o select -L../.libs/ -lzdb -I../zdb select.c
You can download the C++ compatible version from
http://www.tildeslash.com/libzdb/dist/libzdb-2.10.tar.gz
Please let me know if it works in your project. If it does, I'll keep
the changes so libzdb can be used from C++ in the future.
Best regards
On Oct 27, 2011, at 10:51 AM, Antonio Castellon - RAC wrote:
Wow, I spend too much time to refactoring the code, but it not compile
fine. :-( it's not easy to modify the problem with the typedef structs definition...or perhaps i'm wrong and it is more easy than I found.... could you check if it is more complicated? if not, I will forced to search to another library to be used on my project :-(
thanks for all toni
On Thu, Oct 27, 2011 at 06:25, Antonio Castellon - RAC <
antonio.castellon.rac@gmail.com> wrote:
Dear Jan,
First of all, thanks for your answers. I don't want to evaluate if C is
better than C++, on my particular case, I have need to integrate the libzdb into a framework of C++. Perhaps If you are interested (and if it is possible), I could modify the headers of this API according to C++ compatibility and send to the packet in order that you include (not substitute) this new header files as a complement for future users that has the same problem than me.
Very thanks for your support, Best regards Toni
-- To unsubscribe: http://www.tildeslash.com/mailman/listinfo/libzdb-general