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

Build failures on MSVC #772

Closed
reid-p opened this issue Dec 9, 2021 · 11 comments
Closed

Build failures on MSVC #772

reid-p opened this issue Dec 9, 2021 · 11 comments

Comments

@reid-p
Copy link

reid-p commented Dec 9, 2021

With the pattern change from
#if WITH_USB_BACKEND
..
#endif
to
if (WITH_USB_BACKEND) {
....
}

I'm getting linker errors related to usb_context_scan() etc.

MSVC compiler is not smart enough to do dead code removal, or I haven't found the right switches.
Been some other reports in for different libraries of the same issue with MSVC.

Thoughts?

@rgetz
Copy link
Contributor

rgetz commented Dec 10, 2021

my thought is don’t modify the source so that it breaks. Sorry - we aren’t general purpose MSVC support - it has issues , but is popular enough we work around them.

The code as is - works. On purpose. We do it that way - not because it is pretty, but because it’s functional.

  • Robin

@reid-p
Copy link
Author

reid-p commented Dec 12, 2021

G'day rgetz,

Sorry let me be more clear. I haven't modified the source.
With commit c10d6e3
treewide: Avoid conditional compilation

msvc 2019 fails to compile libiio. The is due to the pattern change.
#if WITH_USB_BACKEND
..
#endif
to
if (WITH_USB_BACKEND) {
....
}

Prior to this commit it builds and links ok for me.

@pcercuei
Copy link
Contributor

Hi @reid-p,
I can reproduce it, this happens when building the library when the cmake build variant is set to Debug. It will succeed to compile if you set it to Release mode, or RelWithDebInfo (if you need the debug symbols).

@reid-p
Copy link
Author

reid-p commented Dec 14, 2021

Thanks @pcercuei

Yeap debug builds are the problem with msvc builds failing.

I was trying to create a vcpkg port for libiio for use with msvc.
Which builds the debug libraries first, and that's what I also used for for independent testing.

Having debug builds has been nice occasionally.

@pcercuei
Copy link
Contributor

@reid-p The problem is that MSVC in debug mode is just very stupid. If it sees this code:

if (0)
   call_function();

It will try to link against the call_function symbol even though it's clearly dead code.

I believe for your vcpkg, you should build in RelWithDebInfo mode. The "solution" in our case would be to disable the Debug mode completely.

@rgetz
Copy link
Contributor

rgetz commented Feb 17, 2022

@pcercuei Can we disable Debug mode in MSVC?

@pcercuei
Copy link
Contributor

@rgetz I tried but failed, MSVC has a "Debug" mode even when CMake doesn't have one.

@rgetz
Copy link
Contributor

rgetz commented Feb 17, 2022

so, do we just document (in the README_BUILD.md) and close?

@pcercuei
Copy link
Contributor

Yes, but maybe leave this bug report open until the README_BUILD.md is updated.

@rgetz
Copy link
Contributor

rgetz commented Feb 21, 2022

Added #798

@rgetz rgetz closed this as completed Feb 22, 2022
rgetz added a commit that referenced this issue Apr 6, 2022
gcc and clang always build with '-g', enabling easier debugging, so
catch MSVC to the same.

This will create seperate program database (.pdb) files, which map
identifiers and statements in the project's source code to
corresponding identifiers and instructions in compiled apps.
These mapping files link the debugger to your source code, which
enables debugging.

Hopefully this will put a stop to those who want to build in windows
in debug mode (which is not possible, see #772)

This does not include the pdb files in the installers, so the only way
to get them is build locally.

Signed-off-by: Robin Getz <[email protected]>
rgetz added a commit that referenced this issue Apr 6, 2022
gcc and clang always build with '-g', enabling easier debugging, so
catch MSVC to the same.

This will create seperate program database (.pdb) files, which map
identifiers and statements in the project's source code to
corresponding identifiers and instructions in compiled apps.
These mapping files link the debugger to your source code, which
enables debugging.

Hopefully this will put a stop to those who want to build in windows
in debug mode (which is not possible, see #772)

This does not include the pdb files in the installers, so the only way
to get them is build locally.

Signed-off-by: Robin Getz <[email protected]>
rgetz added a commit that referenced this issue Apr 6, 2022
gcc and clang always build with '-g', enabling easier debugging, so
catch MSVC to the same.

This will create seperate program database (.pdb) files, which map
identifiers and statements in the project's source code to
corresponding identifiers and instructions in compiled apps.
These mapping files link the debugger to your source code, which
enables debugging.

Hopefully this will put a stop to those who want to build in windows
in debug mode (which is not possible, see #772)

This does not include the pdb files in the installers, so the only way
to get them is build locally.

Signed-off-by: Robin Getz <[email protected]>
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

3 participants