Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler errors in a simple program that uses Windows.h in version 3.3.0 #217

Closed
lmiguelmh opened this issue Mar 9, 2016 · 8 comments
Closed

Comments

@lmiguelmh
Copy link

A simple program like this was compiling and executing fine in version 3.2.3.

#pragma comment(lib, "user32")
#include <windows.h>
int main() {
     MessageBox(NULL, "hello world", "", 0);
    return 0;
}

The problem arises when using 3.3.0 (published the 29-Feb-2016 in the maven central repository).

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>lmiguelmh.test</groupId>
    <artifactId>msgbox-app</artifactId>
    <version>1.0</version>
    <packaging>nar</packaging>
    <build>
        <plugins>
            <plugin>
                <groupId>com.github.maven-nar</groupId>
                <artifactId>nar-maven-plugin</artifactId>
                <version>3.3.0</version>
                <extensions>true</extensions>
                <configuration>
                    <libraries>
                        <library>
                            <type>executable</type>
                            <run>true</run>
                        </library>
                    </libraries>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Will give a lot of errors:

[INFO] C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1243) : error C2065: 'SAL_sameIRQL' : undeclared identifier
[ERROR] C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1243) : error C2065: 'SAL_sameIRQL' : undeclared identifier
[INFO] C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1246) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
[ERROR] C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1246) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
[INFO] C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1246) : error C2513: 'int' : no variable declared before '='
[ERROR] C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1246) : error C2513: 'int' : no variable declared before '='
[INFO] C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1246) : error C2146: syntax error : missing ';' before identifier 'EXCEPTION_DISPOSITION'
[ERROR] C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1246) : error C2146: syntax error : missing ';' before identifier 'EXCEPTION_DISPOSITION'
[INFO] C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1246) : error C2143: syntax error : missing ';' before '__stdcall'
[ERROR] C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1246) : error C2143: syntax error : missing ';' before '__stdcall'
...

@lmiguelmh
Copy link
Author

Ok, after reading the detailed output of the commands I think I have identified the problem.

When I was using the version 3.2.3 the plugin didn't have a functionality to detect the Windows SDK/Visual Studio, so you had to configure manually your tools first. See: http://stackoverflow.com/a/34658125/2692914

It appears to me that in version 3.3.0 the plugin tries to detect the Windows SDK/Visual Studio versions, so if you have more than one: it will select the first it encounters? In my case:

[DEBUG]  -- Searching for usable VisualStudio 
[DEBUG]  VisualStudio 11.0 (110) found C:\Program Files (x86)\Microsoft Visual Studio 11.0 
[DEBUG]  VisualStudio 9.0 (90) found C:\Program Files (x86)\Microsoft Visual Studio 9.0 
[DEBUG]  -- Searching for usable WindowSDK 
[DEBUG]  WindowSDK 5.0 found C:\Program Files (x86)\Microsoft SDKs\Windows\v5.0
[DEBUG]  WindowSDK 7.1A found C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A
[DEBUG]  WindowSDK 8.0 found C:\Program Files (x86)\Windows Kits\8.0
[DEBUG]  WindowSDK 6.0A found C:\Program Files\Microsoft SDKs\Windows\v6.0A
[DEBUG]  Using WindowSDK 8.0 found C:\Program Files (x86)\Windows Kits\8.0
[INFO] Using AOL: x86-Windows-msvc
[DEBUG] Using linker version: 9.0

So, is there a way to override this automatic detection? For example, when you need to use some specific Windows SDK/Visual Studio compiler.

@GregDomjan
Copy link
Member

A check-in for 3.3.0 to supporting win10 sdk which had some backward compatibility issue.
Perhaps you could take a look at #201 pull request and offer some suggestions on how well this resolution works for you.

Rather than taking "whatever is in the environment" the 3.3.0 process will look for latest tools.

One option to override would be "by specific path" - this prevents the search

<linker>
    <toolPath>C:\Program Files (x86)\Microsoft Visual Studio 9.0</toolPath>
    <cpp>
        <toolPath>C:\Program Files (x86)\Microsoft Visual Studio 9.0</toolPath>
    </cpp>
</linker>

Another better option not working in 3.3.0 is to specify the version desired

        <msvc>
            <version>11.0</version>
            <windowsSdkVersion>8.0</windowsSdkVersion>
        </msvc>

@lmiguelmh
Copy link
Author

Thanks for your response.

I am not sured what happened but it worked with 3.3.0 and <msvc>...</msvc>:

  <build>
        <plugins>
            <plugin>
                <groupId>com.github.maven-nar</groupId>
                <artifactId>nar-maven-plugin</artifactId>
                <version>3.3.0</version>
                <extensions>true</extensions>
                <configuration>
                    <libraries>
                        <library>
                            <type>executable</type>
                            <run>true</run>
                        </library>
                    </libraries>
                    <msvc>
                        <version>11.0</version>
                        <windowsSdkVersion>8.0</windowsSdkVersion>
                    </msvc>
                </configuration>
            </plugin>
        </plugins>
    </build>

As a side note, maybe it will be better to look for paths or tools only when the user hasn't configured its tools. For example, executing where cl and getting a valid response could indicate that the user configured its tools (Developer Command Prompt for VS2012.bat or VS2012 ARM Cross Tools Command Prompt.bat or VS2012 x64 Native Tools Command Prompt.bat or VS2012 x64 Cross Tools Command Prompt.bat).

Thanks a lot for your answer!

@Oneplus
Copy link
Contributor

Oneplus commented Mar 30, 2016

Found the same issue when the system has more than one VS.

I traced the code and found in Msvc.java line 299:
if (version.compareTo(this.version) > 0) {
which thinks that VisualStudio 9.0 (90) is greater than VisualStudio 11.0 (110).

However, conceptionally, VisualStudio 11.0 (110) should be greater than VisualStudio 9.0 (90), so maybe a versionComparator is also needed to decide the MSVC compiler.

@Oneplus
Copy link
Contributor

Oneplus commented Mar 30, 2016

qq photo20160330225236

there is the screenshot of debug log on appveyor ci. Its virtual machine has VS9 VS10 VS12 and a bunch of winsdks. It seems nar-maven plugin are using VS9 and winsdk 8.1 and these two seems not match.

Oneplus added a commit to Oneplus/nar-maven-plugin that referenced this issue Mar 30, 2016
Oneplus added a commit to Oneplus/nar-maven-plugin that referenced this issue Mar 30, 2016
@ctrueden
Copy link
Contributor

I merged @Oneplus's PR #220.

@lmiguelmh: can you please give it a try and see if this issue is resolved with your system configuration?

@lmiguelmh
Copy link
Author

lmiguelmh commented Apr 22, 2016

Hi guys sorry for the late answer.
I think the problem was fixed. This is the detailed output of mvn -X clean compile in 3.4.1-SNAPSHOT

[DEBUG] -- Searching for usable VisualStudio
[DEBUG] VisualStudio 11.0 (110) found C:\Program Files (x86)\Microsoft Visual Studio 11.0
[DEBUG] -- Searching for usable WindowSDK
[DEBUG] ...
...
[INFO] BUILD SUCCESS

This was the result when executing mvn -X clean compile in 3.4.0

[DEBUG] -- Searching for usable VisualStudio
[DEBUG] VisualStudio 11.0 (110) found C:\Program Files (x86)\Microsoft Visual Studio 11.0
[DEBUG] VisualStudio 9.0 (90) found C:\Program Files (x86)\Microsoft Visual Studio 9.0
[DEBUG] -- Searching for usable WindowSDK
[DEBUG] ...

Thanks again. The problem is fixed.

@ctrueden
Copy link
Contributor

Awesome, thanks for following up @lmiguelmh.

heathn pushed a commit to heathn/nar-maven-plugin that referenced this issue Mar 30, 2018
heathn pushed a commit to heathn/nar-maven-plugin that referenced this issue Mar 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants