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

Failed to compile on Windows 10 #82

Closed
jwreep opened this issue Dec 5, 2023 · 9 comments
Closed

Failed to compile on Windows 10 #82

jwreep opened this issue Dec 5, 2023 · 9 comments

Comments

@jwreep
Copy link
Member

jwreep commented Dec 5, 2023

Fresh install. I've added all dependencies and C++ is compiling in general, but I get the following when trying to compile ebtel++

(base) C:\Users\reep\Documents\ebtelPlusPlus-main>scons
C:\Users\reep\anaconda3\Scripts\scons.py:104: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  import pkg_resources
scons: Reading SConscript files ...

scons: warning: No version of Visual Studio compiler found - C/C++ compilers most likely not set correctly
File "C:\Users\reep\Documents\ebtelPlusPlus-main\SConstruct", line 30, in <module>
Unrecognized platform. Using Windows compile options.

scons: warning: No version of Visual Studio compiler found - C/C++ compilers most likely not set correctly
File "C:\Users\reep\Documents\ebtelPlusPlus-main\source\SConscript", line 7, in <module>

scons: *** An executable should have exactly one target with the suffix: .exe
File "C:\Users\reep\Documents\ebtelPlusPlus-main\SConstruct", line 66, in <module>

It looks like it's not using gcc? g++ is working on this computer:

(base) C:\Users\reep\Documents\C++ test>g++ main.cpp -o main.exe

(base) C:\Users\reep\Documents\C++ test>main.exe
Hello world!!

Are there other options required to install with cygwin? Or is the issue something else? Not sure I understand the error message about one target exe.

@wtbarnes
Copy link
Member

wtbarnes commented Dec 5, 2023

Odd, I've never come across this before. I just recently helped someone install and run this on Windows and did not come across this error message.

What version of scons are you using? (scons --version)

@jwreep
Copy link
Member Author

jwreep commented Dec 5, 2023

Working on debugging it. I think there's a few errors embedded here, which seem to be pathing related.

C:\Users\reep\anaconda3\Scripts\scons.py:104: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  import pkg_resources
SCons by Steven Knight et al.:
        script: v3.1.2.bee7caf9defd6e108fc2998a2520ddb36a967691, 2019-12-17 02:07:09, by bdeegan on octodog
        engine: v3.1.2.bee7caf9defd6e108fc2998a2520ddb36a967691, 2019-12-17 02:07:09, by bdeegan on octodog
        engine path: ['C:\\Users\\reep\\anaconda3\\Lib\\site-packages\\SCons']
Copyright (c) 2001 - 2019 The SCons Foundation

@jwreep
Copy link
Member Author

jwreep commented Dec 5, 2023

I was able to compile my hello world program with scons, but had to add the following to Sconstruct so that it could find g++:

env = Environment(tools=['g++','gnulink'])
env.PrependENVPath('PATH','C:/cygwin64/bin')
env.Program('main.cpp')

@jwreep
Copy link
Member Author

jwreep commented Dec 5, 2023

In the Sconstruct file, I think that this line should explicitly declare the output file format:
env = Environment(CXX=CXX, CXXFLAGS=cxx_flags)
like so
env = Environment(CXX=CXX, CXXFLAGS=cxx_flags, PROGSUFFIX='.run')

After doing so, the exe error is replaced by another

scons: done reading SConscript files.
scons: Building targets ...
g++ /Fosource\dem.obj /c source\dem.cpp -std=c++11 -O3 /nologo /IC:\usr\local\include
'g++' is not recognized as an internal or external command,
operable program or batch file.
scons: *** [source\dem.obj] Error 1
scons: building terminated because of errors.

And then adding similar lines to get it to detect g++,

else:
    print("Unrecognized platform. Using Windows compile options.")
    env.PrependENVPath('PATH','C:/cygwin64/bin')
    env.Append(tools=['g++','gnulink'])
    env.Append(CPPPATH=['/usr/local/include'])
    env.Append(LIBS=['boost_program_options'])
    env.Append(LIBPATH=['/usr/local/lib'])

The error is replaced by one more error, which I can't figure out.

scons: done reading SConscript files.
scons: Building targets ...
g++ /Fosource\dem.obj /c source\dem.cpp -std=c++11 -O3 /nologo /IC:\usr\local\include
source\dem.cpp:6:10: fatal error: dem.h: No such file or directory
    6 | #include "dem.h"
      |          ^~~~~~~
compilation terminated.
scons: *** [source\dem.obj] Error 1
scons: building terminated because of errors.

@jwreep
Copy link
Member Author

jwreep commented Dec 7, 2023

I think I've figured it out. I got it to compile and run. There were a bunch of issues:

  1. SCons assumes Visual C++ compiler and compiler options by default, so if using MinGW or Cygwin we need to specify to use appropriate gcc options (e.g. -o rather than /Fo). This can be done in the env variable by setting e.g. env = Environment(CXX=CXX, CXXFLAGS=cxx_flags, PROGSUFFIX='.run', tools=["mingw"]). Perhaps env.Append(tools=["mingw"]) under the Windows section is better.
  2. The Boost library can be installed directly through Cygwin. I think it was having trouble finding the library when I installed it through conda. I see there's a note in the docs about explicitly telling it the path that I missed before.
  3. I had to specify full paths in SConstruct to Cygwin (e.g. C:\\cygwin64\\usr\\include)
  4. For some reason, SCons required full paths for the header files. That is, in dem.cpp, it required #include "source/dem.h" rather than #include "dem.h". I had to change the header includes in all of the cpp files.
  5. This is in addition to the changes noted in my previous post.

I think resolving this issue would require that we modify the SConstruct file and the .cpp files under /source/, but I would want to test that any change still works under Mac/Linux (waiting on a new Mac to be shipped, but I don't currently have access to a Linux box). I'd also like to confirm whether others have the same issue on Windows, or if user error was involved!

@wtbarnes
Copy link
Member

wtbarnes commented Dec 8, 2023

I'm really confused by what's going on here, particularly point number 4. I just recently helped someone install gcc and boost through Cygwin and compile ebtel++ on Windows without any changes to the scons file or even specifying any additional paths so I'm pretty sure this should be possible.

It looks like the latest version of scons is 4.5.2, but you're on version 3.1.2. Could you update scons and try compiling with the unmodified SConstruct file and see if that makes any difference? The one thing you may need to do is set the CXX env variable to point at the g++ compiler you installed with Cygwin if you've not already done so.

@jwreep
Copy link
Member Author

jwreep commented Dec 11, 2023

Right, so I updated to the newest Scons (4.6.0) and it didn't make a difference. (As a sidenote, conda was only updating to 3.1.2 -- don't know why it didn't give the latest.) I don't know why this particular machine (or more likely user) is having issues with it.

Point 3 in my list above was unnecessary, but everything else still persisted. I've attached the SConstruct that made everything work, but don't fully understand why "source/dem.h" etc. was needed in the C++ files.

SConstruct.txt

@wtbarnes
Copy link
Member

wtbarnes commented Dec 27, 2023

This is still really puzzling to me, but I'm happy to incorporate any needed kludges to the SConstruct file in order to get things working on Windows, particularly since I don't have a Windows machine to test this on myself. I'm increasingly unhappy with scons as a build tool and the need to install boost is obviously a real pain.

Based on this and #84, I think providing pre-built binaries with Python bindings is probably the way to go as it would alleviate any platform-specific issues and would greatly simplify the installation process. I've started experimenting with this in #79 and would be happy to have some Windows testers.

@wtbarnes
Copy link
Member

wtbarnes commented Sep 8, 2024

Closing as solved by #98. If the provided binaries don't acutally solve this issue, happy to reopen!

@wtbarnes wtbarnes closed this as completed Sep 8, 2024
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

2 participants