Skip to content

fix w64-mingw32-ld linking error#3184

Merged
danmar merged 2 commits intocppcheck-opensource:mainfrom
DGarry82:mingw-shlwapi-fix
Mar 29, 2021
Merged

fix w64-mingw32-ld linking error#3184
danmar merged 2 commits intocppcheck-opensource:mainfrom
DGarry82:mingw-shlwapi-fix

Conversation

@DGarry82
Copy link
Copy Markdown
Contributor

use shlwapi instead of Shlwapi.lib in mingw-w64 build environment
(prevents "/usr/bin/x86_64-w64-mingw32-ld: cannot find -lShlwapi" error)

[100%] Linking CXX executable ../bin/cppcheck.exe
/usr/bin/x86_64-w64-mingw32-ld: cannot find -lShlwapi
collect2: error: ld returned 1 exit status
make[6]: *** [cli/CMakeFiles/cppcheck.dir/build.make:225: bin/cppcheck.exe] Error 1

$ dpkg-query -S /usr/x86_64-w64-mingw32/lib/libshlwapi.a
mingw-w64-x86-64-dev: /usr/x86_64-w64-mingw32/lib/libshlwapi.a

$ dpkg -l|grep mingw-w64
ii binutils-mingw-w64-i686 2.30-7ubuntu1+8ubuntu1 amd64 Cross-binutils for Win32 (x86) using MinGW-w64
ii binutils-mingw-w64-x86-64 2.30-7ubuntu1+8ubuntu1 amd64 Cross-binutils for Win64 (x64) using MinGW-w64
ii g++-mingw-w64-i686 5.3.1-8ubuntu3+17 amd64 GNU C++ compiler for MinGW-w64 targeting Win32
ii g++-mingw-w64-x86-64 5.3.1-8ubuntu3+17 amd64 GNU C++ compiler for MinGW-w64 targeting Win64
ii gcc-mingw-w64-base 5.3.1-8ubuntu3+17 amd64 GNU Compiler Collection for MinGW-w64 (base package)
ii gcc-mingw-w64-i686 5.3.1-8ubuntu3+17 amd64 GNU C compiler for MinGW-w64 targeting Win32
ii gcc-mingw-w64-x86-64 5.3.1-8ubuntu3+17 amd64 GNU C compiler for MinGW-w64 targeting Win64
ii mingw-w64-common 5.0.3-1 all Common files for Mingw-w64
ii mingw-w64-i686-dev 5.0.3-1 all Development files for MinGW-w64 targeting Win32
ii mingw-w64-x86-64-dev 5.0.3-1 all Development files for MinGW-w64 targeting Win64

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic

use shlwapi instead of Shlwapi.lib in mingw-w64 build environment
(prevents "/usr/bin/x86_64-w64-mingw32-ld: cannot find -lShlwapi" error)
@firewave firewave self-assigned this Mar 26, 2021
@firewave firewave self-requested a review March 26, 2021 15:16
Copy link
Copy Markdown
Collaborator

@firewave firewave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also needs to be done in test/CMakeLists.txt and tools/CMakeLists.txt.

For MinGW it will actually work without the .lib suffix - that is only required for MSVC. So the code should actually be

if(MSVC)
    target_link_libraries(cppcheck Shlwapi.lib)
else()
    target_link_libraries(cppcheck shlwapi)
endif()

@firewave
Copy link
Copy Markdown
Collaborator

firewave commented Mar 26, 2021

Thanks for your contribution.

I see - the cross-compilation doesn't work. Was baffled since MinGW links fine locally for me - on Windows.

Also something to considered for the CI build matrix.

@DGarry82 DGarry82 force-pushed the mingw-shlwapi-fix branch from d3fabad to c2d4609 Compare March 29, 2021 07:45
@DGarry82 DGarry82 force-pushed the mingw-shlwapi-fix branch from c2d4609 to 97a66e3 Compare March 29, 2021 07:46
@DGarry82
Copy link
Copy Markdown
Contributor Author

DGarry82 commented Mar 29, 2021

This also needs to be done in test/CMakeLists.txt and tools/CMakeLists.txt.

Done.

@DGarry82
Copy link
Copy Markdown
Contributor Author

Also something to considered for the CI build matrix.

Do you mean some additional testing environment for cross-compilation?

@DGarry82 DGarry82 requested a review from firewave March 29, 2021 10:15
@firewave
Copy link
Copy Markdown
Collaborator

Also something to considered for the CI build matrix.

Do you mean some additional testing environment for cross-compilation?

Yes, currently there is no cross-compilation done at all in the CI.

Copy link
Copy Markdown
Collaborator

@firewave firewave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine. Will apply the inverted MSVC checks later on.

@danmar danmar merged commit 77716ee into cppcheck-opensource:main Mar 29, 2021
@DGarry82 DGarry82 deleted the mingw-shlwapi-fix branch March 29, 2021 15:18
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

Successfully merging this pull request may close these issues.

3 participants