error while converting to cmake - kooldock.cpp - iostream #2

Closed
opened 6 years ago by Ghost · 15 comments
Ghost commented 6 years ago

While converting kooldock from automake to cmake I ran against this error:

/usr/include/c++/6.5.0/bits/basic_string.h: In member function 'int std::basic_string<_CharT, _Traits, _Alloc>::compare(const std::basic_string<_CharT, _Traits, _Alloc>&) const': /home/cethyel/Public/trinity-pot/CMAKECONV/kooldock/src/kooldock.cpp:66:19: error: expected unqualified-id before '(' token #define min(a, b) (a < b) ? (a) : (b)

I get rid of this error by removing "#include <iostream>" from kooldock.cpp
It builds fine and kooldock seems to be working fine but I'd like to have your view on the matter.

While converting kooldock from automake to cmake I ran against this error: <code> /usr/include/c++/6.5.0/bits/basic_string.h: In member function 'int std::basic_string<_CharT, _Traits, _Alloc>::compare(const std::basic_string<_CharT, _Traits, _Alloc>&) const': /home/cethyel/Public/trinity-pot/CMAKECONV/kooldock/src/kooldock.cpp:66:19: error: expected unqualified-id before '(' token #define min(a, b) (a < b) ? (a) : (b) </code> I get rid of this error by removing "#include \<iostream\>" from kooldock.cpp It builds fine and kooldock seems to be working fine but I'd like to have your view on the matter.
Owner

uhm.. sounds a bit weird to say the least. Although if it works.... 😄

uhm.. sounds a bit weird to say the least. Although if it works.... :smile:
Ghost commented 6 years ago
Poster

I also tried with automake and kooldock builds fine without but I have basically no ideas where that include is needed.

I also tried with automake and kooldock builds fine without but I have basically no ideas where that include is needed.
Ghost commented 6 years ago
Poster

I read that actually iostream loads a bunch of headers, if I could replace It with what is needed only, perhaps I won't run against that error (which is a blocker for the cmake conversion) while keeping everything to work as intended by the author of the code.

I read that actually iostream loads a bunch of headers, if I could replace It with what is needed only, perhaps I won't run against that error (which is a blocker for the cmake conversion) while keeping everything to work as intended by the author of the code.
Owner

the problem is not the include file itself. it is understanding why there is no error in autotools and instead it comes up with an error when using cmake. There must be something going on that we are missing I guess.

the problem is not the include file itself. it is understanding why there is no error in autotools and instead it comes up with an error when using cmake. There must be something going on that we are missing I guess.
Ghost commented 6 years ago
Poster

I ran a quick search on the file with the usual/basic functions that (i)ostream provides but after 3/4 without result I just gave up.

I ran a quick search on the file with the usual/basic functions that (i)ostream provides but after 3/4 without result I just gave up.
Owner

I did a quick search through the code and it seems iostream include file is not required actually. Perhaps not the ideal solution, but it could be just simpler to remove that include file and continue instead of wasting time chasing this further, which is what you you suggested initially 😄

I did a quick search through the code and it seems iostream include file is not required actually. Perhaps not the ideal solution, but it could be just simpler to remove that include file and continue instead of wasting time chasing this further, which is what you you suggested initially :smile:
Owner

This problem could be casued by different compiling mode when switching from autotools to cmake.

Twice in the past I ran into issue when building a .c file and adding some includes and switching to .cpp. Or viceversa. Perhaps it is something like this.

This problem could be casued by different compiling mode when switching from autotools to cmake. Twice in the past I ran into issue when building a .c file and adding some includes and switching to .cpp. Or viceversa. Perhaps it is something like this.
Ghost commented 6 years ago
Poster

Graham Seed in a book said that he not very fond of #define min or #define max as macro, instead he prefers templates such as this one:
template T max( T a, T b) { return a > b ? a : b ;}
on the other hand, I should give an other try with new parenthesis, from his book:
#define max(a, b) (( a > b ) ? a : b )
...to be continued!

Graham Seed in a book said that he not very fond of #define min or #define max as macro, instead he prefers templates such as this one: <code>template <class T> T max( T a, T b) { return a > b ? a : b ;}</code> on the other hand, I should give an other try with new parenthesis, from his book: <code>#define max(a, b) (( a > b ) ? a : b )</code> ...to be continued!
Collaborator

Holly cow! Just ditch the macros and use std::min()/std::max() already…

Holly cow! Just ditch the macros and use [std::min()](https://en.cppreference.com/w/cpp/algorithm/min)/[std::max()](https://en.cppreference.com/w/cpp/algorithm/max) already…
Ghost commented 6 years ago
Poster

@Fat-Zer
I usually don't touch the code because I've had little understanding of what's going on in programming in general but out of curiosity, I'll have a look on the links you've provided.
Anyhow, thanks for your input on the matter.
Feel free to help me out and submit a PR to get rid of those pesky macros.

@Fat-Zer I usually don't touch the code because I've had little understanding of what's going on in programming in general but out of curiosity, I'll have a look on the links you've provided. Anyhow, thanks for your input on the matter. Feel free to help me out and submit a PR to get rid of those pesky macros.
Collaborator

@cethyel, lol, I knew that was coming... I'll base upon your feat/cmakeConv branch and PR directly to it to not to clobber with your pending PR if you don't mind...

PS: nice work converting to cmake

@cethyel, lol, I knew that was coming... I'll base upon your `feat/cmakeConv` branch and PR directly to it to not to clobber with your pending PR if you don't mind... PS: nice work converting to cmake
Collaborator

Woops... @cethyel, it looks like I've accidentally pushed directly to feat/cmakeConv... I didn't suspected I've got the perms... I hope you don't mind... otherwise sorry about that...

Woops... @cethyel, it looks like I've accidentally pushed directly to `feat/cmakeConv`... I didn't suspected I've got the perms... I hope you don't mind... otherwise sorry about that...
Ghost commented 6 years ago
Poster

@Fat-Zer That's cool as It is, you rock man!

@Fat-Zer That's cool as It is, you rock man!
Owner

@Fat-Zer, you are included in the team of contributors, which means that you can push the branches directly into the main repositories == there is no need to make forks… as is described in the wiki for TDE Gitea Workspace.

@Fat-Zer, you are included in the team of contributors, which means that you can push the branches directly into the main repositories == there is no need to make forks… as is described in the wiki for [TDE Gitea Workspace](https://wiki.trinitydesktop.org/TDE_Gitea_Workspace).
SlavekB added a new dependency 6 years ago
Owner

Resolved by commits in #4 – thank you all for your cooperation!

Resolved by commits in #4 – thank you all for your cooperation!
SlavekB closed this issue 6 years ago
SlavekB added this to the R14.1.0 release milestone 6 years ago
Sign in to join this conversation.
No Milestone
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Depends on
Reference: TDE/kooldock#2
Loading…
There is no content yet.