orca-zhang / influxdb-cpp

💜 C++ client for InfluxDB.
MIT License
163 stars 83 forks source link

Does not handle being included more than once in application sources. #7

Closed mwinters-stuff closed 6 years ago

mwinters-stuff commented 6 years ago

First issue is there is no "#pragma once" or #ifndef block around the header to make sure that it can handle being included more than once.

Second, as my app includes the header and uses it in more than once cpp file, the linking failed with

build/debug/obj/main.o: In functioninfluxdb_cpp::detail::to_hex(unsigned char)': main.cc:(.text+0x0): multiple definition of influxdb_cpp::detail::to_hex(unsigned char)' build/debug/obj/firebase.o:firebase.cc:(.text+0xccc): first defined here build/debug/obj/main.o: In functioninfluxdb_cpp::detail::url_encode(std::string&, std::string const&)': main.cc:(.text+0x14): multiple definition of influxdb_cpp::detail::url_encode(std::string&, std::string const&)' build/debug/obj/firebase.o:firebase.cc:(.text+0xce0): first defined here build/debug/obj/main.o: In functioninfluxdb_cpp::detail::http_request(char const, char const, std::string const&, std::string const&, influxdb_cpp::server_info const&, std::string)': main.cc:(.text+0x210): multiple definition of `influxdb_cpp::detail::http_request(char const, char const, std::string const&, std::string const&, influxdb_cpp::server_info const&, std::string)' build/debug/obj/firebase.o:firebase.cc:(.text+0xedc): first defined here build/debug/obj/main.o: In function influxdb_cpp::query(std::string&, std::string const&, influxdb_cpp::server_info const&)': main.cc:(.text+0x2054): multiple definition ofinfluxdb_cpp::query(std::string&, std::string const&, influxdb_cpp::server_info const&)' build/debug/obj/firebase.o:firebase.cc:(.text+0x2d20): first defined here build/debug/obj/main.o: In function influxdb_cpp::create_db(std::string&, std::string const&, influxdb_cpp::server_info const&)': main.cc:(.text+0x2220): multiple definition ofinfluxdb_cpp::create_db(std::string&, std::string const&, influxdb_cpp::server_info const&)' build/debug/obj/firebase.o:firebase.cc:(.text+0x2eec): first defined here build/debug/obj/decodereadings.o: In function influxdb_cpp::detail::to_hex(unsigned char)': decodereadings.cc:(.text+0x70): multiple definition ofinfluxdb_cpp::detail::to_hex(unsigned char)' build/debug/obj/firebase.o:firebase.cc:(.text+0xccc): first defined here build/debug/obj/decodereadings.o: In function influxdb_cpp::detail::url_encode(std::string&, std::string const&)': decodereadings.cc:(.text+0x84): multiple definition ofinfluxdb_cpp::detail::url_encode(std::string&, std::string const&)' build/debug/obj/firebase.o:firebase.cc:(.text+0xce0): first defined here build/debug/obj/decodereadings.o: In function influxdb_cpp::detail::http_request(char const*, char const*, std::string const&, std::string const&, influxdb_cpp::server_info const&, std::string*)': decodereadings.cc:(.text+0x280): multiple definition ofinfluxdb_cpp::detail::http_request(char const, char const, std::string const&, std::string const&, influxdb_cpp::server_info const&, std::string)' build/debug/obj/firebase.o:firebase.cc:(.text+0xedc): first defined here build/debug/obj/decodereadings.o: In function influxdb_cpp::query(std::string&, std::string const&, influxdb_cpp::server_info const&)': decodereadings.cc:(.text+0x2070): multiple definition ofinfluxdb_cpp::query(std::string&, std::string const&, influxdb_cpp::server_info const&)' build/debug/obj/firebase.o:firebase.cc:(.text+0x2d20): first defined here build/debug/obj/decodereadings.o: In function influxdb_cpp::create_db(std::string&, std::string const&, influxdb_cpp::server_info const&)': decodereadings.cc:(.text+0x223c): multiple definition ofinfluxdb_cpp::create_db(std::string&, std::string const&, influxdb_cpp::server_info const&)' build/debug/obj/firebase.o:firebase.cc:(.text+0x2eec): first defined here build/debug/obj/radiohandler.o: In function influxdb_cpp::detail::to_hex(unsigned char)': radiohandler.cc:(.text+0x2ec): multiple definition ofinfluxdb_cpp::detail::to_hex(unsigned char)' build/debug/obj/firebase.o:firebase.cc:(.text+0xccc): first defined here build/debug/obj/radiohandler.o: In function influxdb_cpp::detail::url_encode(std::string&, std::string const&)': radiohandler.cc:(.text+0x300): multiple definition ofinfluxdb_cpp::detail::url_encode(std::string&, std::string const&)' build/debug/obj/firebase.o:firebase.cc:(.text+0xce0): first defined here build/debug/obj/radiohandler.o: In function `influxdb_cpp::detail::http_request(char const, char const, std::string const&, std::string const&, influxdb_cpp::server_info const&, std::string)': radiohandler.cc:(.text+0x4fc): multiple definition of influxdb_cpp::detail::http_request(char const*, char const*, std::string const&, std::string const&, influxdb_cpp::server_info const&, std::string*)' build/debug/obj/firebase.o:firebase.cc:(.text+0xedc): first defined here build/debug/obj/radiohandler.o: In functioninfluxdb_cpp::query(std::string&, std::string const&, influxdb_cpp::server_info const&)': radiohandler.cc:(.text+0x2340): multiple definition of influxdb_cpp::query(std::string&, std::string const&, influxdb_cpp::server_info const&)' build/debug/obj/firebase.o:firebase.cc:(.text+0x2d20): first defined here build/debug/obj/radiohandler.o: In functioninfluxdb_cpp::create_db(std::string&, std::string const&, influxdb_cpp::server_info const&)': radiohandler.cc:(.text+0x250c): multiple definition of `influxdb_cpp::create_db(std::string&, std::string const&, influxdb_cpp::server_info const&)' build/debug/obj/firebase.o:firebase.cc:(.text+0x2eec): first defined here collect2: error: ld returned 1 exit status RadioReceiver.make:91: recipe for target 'build/debug/radioreceiver' failed make[1]: [build/debug/radioreceiver] Error 1 Makefile:16: recipe for target 'RadioReceiver' failed make: [RadioReceiver] Error 2

`

Already added #pragma once on my copy, but will have to work on the linking..

orca-zhang commented 6 years ago

Thank you for your feedback. I'll fix it ASAP.

orca-zhang commented 6 years ago

You can try to add 'inline' or 'static' for redefinition functions as a quick fix.

orca-zhang commented 6 years ago

It was fixed by latest commit.

Apologize for my delay cause there was too much work to do this week.