COIN-OR::LEMON - Graph Library

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#612 closed defect (fixed)

Windows compile issue due to macros IN and OUT

Reported by: Peter Kovacs Owned by: Alpar Juttner
Priority: major Milestone: LEMON 1.4 release
Component: core Version: hg main
Keywords: Cc:
Revision id:

Description

Reported by Szabolcs Horvát on the lemon-user mailing list:

The following problem caused me a lot of frustration, so I thought I'd share the solution with the rest of you.

I had some working LEMON-based code that I wrote on OS X, but then couldn't compile on Windows due to a few mysterious errors that seemed to come from the LEMON headers and not my own code.

The problem turned out to be that I was using LEMON in conjunction with a C library, which in turn includes <windows.h> on Windows (obviously not on OS X), which in turn defines the macros IN and OUT. LEMON uses these same names as template parameters, hence the errors.

A simple #undef IN #undef OUT before including any LEMON headers will fix the problem. Doing this appears to be completely safe (perhaps LEMON could do it by default): https://stackoverflow.com/questions/35907493/in-and-out-macros-in-minwindef-h

Szabolcs

Attachments (1)

612-cd72eae05bdf.patch (4.1 KB) - added by Peter Kovacs 6 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 6 years ago by Peter Kovacs

I checked the LEMON sources and adaptors.h is the only file that uses IN and OUT as template typenames. I think it would be better to use different names in LEMON source (e.g. In and Out) than adding #undef.

Changed 6 years ago by Peter Kovacs

Attachment: 612-cd72eae05bdf.patch added

comment:2 Changed 6 years ago by Peter Kovacs

Szabolcs, could you check the attached patch [cd72eae05bdf] if it solves the issue on your machine?

comment:3 Changed 6 years ago by Alpar Juttner

I've been aware of this issue for a long time, but I'm very reluctant to accept these kind of change requests for ideological reason. The real solution to tackle with the nasty habit of polluting the global namespace by VS is to include windows.h on isolated place only and provide the necessary interfaces towards the rest of the code. In fact IN and OUT are not the only problems. Even using identifiers like Arc and _T may cause problems (see #215). Renaming all these would go very far.

On the other hand, approaching to the question pragmatically, I must agree that the proposed change certainly does not harm.

I just want to emphasize here that the problem is not on our side.

comment:4 Changed 6 years ago by Alpar Juttner

#365 mentions other names from which one should abstain on order to be windows.h compatible - TRUE, FALSE and even max and min

comment:5 Changed 6 years ago by Alpar Juttner

Resolution: fixed
Status: newclosed

[cd72eae05bdf] has been merged to branches 1.3 and default.

comment:6 Changed 6 years ago by Peter Kovacs

I agree. This problem was not on our side.

Note: See TracTickets for help on using tickets.