Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Fixed linker errors when included in multiple .cpp files #1

Closed

Conversation

0xFEEDC0DE64
Copy link

Hi,

I was using your library in my project, and when I started including your .h files in multiple .cpp files (compile units), the linker started complaining, as all your symbols where exported from multiple .o files.

I moved your implementations into .cpp files, which allows for linkage instead of inlining, which should not affect performance much.

@khoih-prog
Copy link
Owner

@0xFEEDC0DE64

Thanks so much for using the library and the PR.

The conversion of all xyz.cpp to xyz-Impl.h is intentional to

  1. Let #define in sketch (for example debug, important definitions, etc.) valid anytime when you compile.
  2. You don't have to modify the xyz.cpp just to modify certain options set by #define

You can try to see the feature and why.

Depending on your code, you can have linker complaint sometimes. The solution can be either

  1. Convert you all your code from abc.cpp to abc-Impl.h so that all files are compiled at the same time, not pre-compiled as in the case of abc.cpp.

See the similar problem and solution in Issue 3 of WebSockets2_Generic: multiple definition of `websockets2_generic::WebsocketsServer::~WebsocketsServer()' in websocket2_generic library

  1. Check you code to include the file correctly and only when necessary. This is not possible in all cases.

  2. Convert the library code from xyz-Impl.h back to xyz.cpp as you did.

I won't modify the library back as your PR, but will put a note in README so that anybody having the similar issue can know how to deal.

Certainly I will add a note for your contribution.

Regards,

@khoih-prog khoih-prog closed this Oct 8, 2020
khoih-prog added a commit that referenced this pull request Oct 9, 2020
### Releases v1.0.1

1. Restore cpp code besides Impl.h code to use in case of `multiple definition` linker error. Thanks to [Daniel Brunner](https://github.com/0xFEEDC0DE64) to report and make PR in [**Fixed linker errors when included in multiple .cpp files**](#1). See [**HOWTO Fix `Multiple Definitions` Linker Error**](https://github.com/khoih-prog/AsyncHTTPRequest_Generic#HOWTO-Fix-Multiple-Definitions-Linker-Error)
@khoih-prog
Copy link
Owner

@0xFEEDC0DE64

Just release v1.0.1 to address the issue and add

  1. HOWTO Fix Multiple Definitions Linker Error
  2. Contributions-and-Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants