Page MenuHomePhabricator

Prevent Poco Windows undefs to avoid compile errors in third-party libs
Closed, ResolvedPublic

Description

On Windows POCO include files un-define a few Windows macros by default, e.g. CreateMutex. While this avoids name clashes in third-party code which wants to define e.g. CreateMutex itself, it also leads to the opposite problem of third-party code not compiling anymore if it makes use of such macros.

For BlueBerry/MITK, we use the Windows macros so we prevent their un-definition by compiling our code with -DPOCO_NO_UNWINDOWS. For MITK modules and plug-ins, these compile defintions are already added by the respective macros. For applications, they are missing and may lead to compile errors depending on the set of included MITK header files.

Event Timeline

New remote branch pushed: bug-14623-add-poco-no-unwindows-defines-to-apps

Hi Matt,

I don't have a Windows BlueBerry app ready which exhibits your problems. So, could you maybe check if the pushed branch fixes your errors?

Thanks.

Hi Sascha,

this may not be a good test, however here are my results.

  1. I added

ADD_DEFINITIONS("-DPOCO_NO_UNWINDOWS")

to my app, and it compiled.

  1. I also stashed that and manually added your change to my FunctionCreateBlueBerryApplication.cmae and it compiled.

HOWEVER, in both cases when I run, I get "The procedure entry point GetThreadId could not be located in the dynamic link library KERNEL32.DLL", however, this might be more to do with the fact that my Windows XP 32 bit build it defective for various other reasons. Is this related?

Also, you added IF(WIN32),... do we need that?

Also, you added -DWIN32_LEAN_AND_MEAN .. what does this do?

Thanks

Matt

(In reply to comment #3)

Hi Sascha,

this may not be a good test, however here are my results.

  1. I added

ADD_DEFINITIONS("-DPOCO_NO_UNWINDOWS")

to my app, and it compiled.

  1. I also stashed that and manually added your change to my

FunctionCreateBlueBerryApplication.cmae and it compiled.

Thanks, good enough :-)

HOWEVER, in both cases when I run, I get "The procedure entry point
GetThreadId could not be located in the dynamic link library KERNEL32.DLL",
however, this might be more to do with the fact that my Windows XP 32 bit
build it defective for various other reasons. Is this related?

I haven't seen that one before, but I also haven't tested on Windows XP yet. Does your app run anyway? If yes, I would merge the branch and have a look at that message later.

Also, you added IF(WIN32),... do we need that?

Not really, but I like to not add compile definitions to platforms where they don't make sense...

Also, you added -DWIN32_LEAN_AND_MEAN .. what does this do?

Prevents implicit inclusion of a bunch of headers with rarely used functionality when you include windows.h.

(In reply to comment #4)

I haven't seen that one before, but I also haven't tested on Windows XP yet.
Does your app run anyway? If yes, I would merge the branch and have a look
at that message later.

Unfortunately no. So I can't verify that its not related.
I am asking someone else to do a build on their machine, with just ADD_DEFINITIONS("-DPOCO_NO_UNWINDOWS"), so, if they can run compile and run our app, then I think we can then say that my KERNEL32.DLL is something else.

M

Hi Sascha, sorry for the late reply.

I got a guy called Bjoern on a Win7 64 bit machine to do an update of our NifTK project. This pulled in the new MITK version that we merged yesterday. So, he did a new build of MITK, and NifTK, and got the initial compiler error we had.

He added ADD_DEFINITIONS("-DPOCO_NO_UNWINDOWS"), and could compile NiftyView, and also run it.

This means that my error about Kernel32.dll is unrelated.

So, with Bjoern's evidence, and the fact that I tested both the short term fix to our app, and your change to FunctionCreateBlueberryApplication.cmake, it appears that we have a valid fix for the CreateMutex issue.

Thanks for a speedy response.

Matt

[626784]: Merge branch 'bug-14623-add-poco-no-unwindows-defines-to-apps'

Merged commits:

2013-03-01 14:36:32 Sascha Zelzer [0d6d57]
Add POCO_NO_UNWINDOWS and WIN32_LEAN_AND_MEAN to BlueBerry apps.

(In reply to comment #6)

I got a guy called Bjoern on a Win7 64 bit machine to do an update of our
NifTK project. This pulled in the new MITK version that we merged
yesterday. So, he did a new build of MITK, and NifTK, and got the initial
compiler error we had.

He added ADD_DEFINITIONS("-DPOCO_NO_UNWINDOWS"), and could compile
NiftyView, and also run it.

This means that my error about Kernel32.dll is unrelated.

Okay, thanks for the testing. It may be related to Windows XP though (?) I merged to branch to master but I am still compiling the code on a XP VM to check that it works (XP is not in our continuous integration system).

My Windows XP build no compiled successfully but the application did not run.

This defect was actually introduced by the usage of GetThreadId when working on T13230. Please follow the comment there - thanks.

For the original CreateMutex issue, the macro in the windows headers evaluates to either CreateMutexA or CreateMutexW (for ANSI or Wide character). This difference is only relevant if you are supplying a mutex name.
As you are not giving your mutexes a name (passing NULL) you might just call CreateMutexA directly. I just tested that (before Matt pointed me to this bug entry here). Works.
Whether that is a better or worse workaround, dont know.

Thanks Johannes for your comment. I was aware of the ANSI and wide character variants in the Windows API but wanted to keep the coding style in our libraries consistent (by using the Windows macros) and decided to just disable the "undefs" from Poco so they don't interfere with any of our possible third-party headers (all of them - as far as I know - expect the Windows macros to be available).

Hi,

I had the CreateMutex problem when trying to compile my application as well. Then I added ADD_DEFINITIONS("-DPOCO_NO_UNWINDOWS") and it compiled. When I run my application I get:
"The procedure entry point GetWorldPosition@DisplayPosistionEvent@mitk could not be located in the dynamic link library Mitk.dll", "...GetData@ImageSource@mitk could not be located...".
I am using Windows 7 64-bit.
Regards,
Phan-Anh