Open mtwhite4 opened 5 years ago
Hi Matthew, that is quite odd. It's compiling just fine on my end, and in Travis as well, both with g++ and with clang++. I'm not sure how you could be getting compiler errors. Could you post a pastebin of your main.cc
as well?
One thing that comes to mind: under what C++ standard are you compiling the code? That really shouldn't be the issue (I'd expect many more errors that what you've posted if you're compiling under, say, C++98) though.
My main file below. Pretty much an exact copy of the readme just for testing. I did have to add "config" before the '.Naca' etc because it was throwing errors (error was "expected primary-expression before '.' token). Not sure if that helps narrow things down. I tried running on C++11 and C++14 with the same errors.
The only errors I can reproduce are the first two, which are because of the line double alpha = result["alpha"]
and the one below. The reason for that error is that result
is actually of type unordered_map<string, vector<double>>
, and you were trying to assign the contained vector
s to double
s. That's also how it's currently written in the readme, so I'll get to fixing that. I'll add some more detail to the readme while I'm at it.
The below main file runs without any errors on my end. Are you still getting those syntax errors with this code? If so, I'll spin up a Windows VM and see if I can reproduce there.
#include "CXXfoil/src/xfoil_config.h"
int main() {
cxxfoil::XfoilConfig config("/usr/local/bin/xfoil") ; //Create xfoil object
config.Naca("0015"); //Load specific NACA airfoil;
config.AngleOfAttack(4.0);
config.PaccRandom(); // generates a random file name under /tmp
cxxfoil::XfoilRunner runner = config.GetRunner() ;
cxxfoil::polar result = runner.Dispatch() ;
std::vector<double> alpha_vec = result["alpha"];
std::vector<double> CD_vec = result["CD"];
double alpha = alpha_vec[0];
double CD = CD_vec[0];
// etc, other keys are CL, CDp, CM, Top_Xtr, Bot_Xtr, Top_Itr, Bot_Itr
std::cout << "done" << std::endl;
return 0 ;
}
Thanks for the sample main file and updated readme. I tried running again and I got the same errors are before (excepting the main file ones). I even tried reinstalling my compiler but the issue persists.
Very odd, it must be either a Cygwin or Windows specific thing then. I'll spin up a Windows VM and see what I can do.
I could reproduce your issues on Cygwin. It would seem that the compiler errors were caused by Cygwin or one of its headers globally defining stdin
and stdout
as pointers of some kind, so using those names as members of spawn
was causing the errors. Additionally, it could not find execvpe
(although that should be defined in unistd.h
), so I replaced its usage with one of its relatives. I've also added a check to see whether you're using Cygwin, in which case it passes a different filename to xfoil if you're using PaccRandom()
(since Windows doesn't have a /tmp/
directory).
I've managed to build and run the code successfully under Cygwin; you simply have to pass the XfoilConfig
constructor the path to your xfoil.exe (e.g. "C:/users/jesse/xfoil/xfoil.exe"
) and it should work.
Thank you for all the work you've been doing on this! It now compiles successfully, however I am getting an exception when running.
3 [main] XFOIL_Wrapper 39448 cygwin_exception::open_stackdumpfile: Dumping stack trace to XFOIL_Wrapper.exe.stackdump
I've attached the generated stackdump but don't know how to open it myself.
Main File: https://pastebin.com/TTsdJQU5
The stackdump shows that it crashed due to an access violation... My guess is that xfoil cannot open the polar file, and thus the result vectors are empty, causing the program to die when you try to access their contents.
Does the program still crash when you comment out lines 16, 17 and 20?
P.S. you can just open the stack dump as a regular text file.
So upon commenting out those lines the program cannot run at all. the error the terminal shows is 'Failed to launch program.' Possibly the access violation stems from trying to read files that were never populated since xfoil isn't launching.
No, the access violation is definitely due to the empty vectors, which in turn are empty because Xfoil never ran. Which is strange, since it runs just fine on my Cygwin install. Maybe a stupid question, but are you sure the path to your xfoil.exe you entered is correct? Otherwise, I'm not sure what could be causing execv
to fail.
I've also uploaded a version using system
instead of execv
, in this branch. You could try that one, though it really shouldn't make a difference - system
just calls fork
and execl
. It's worth a shot though.
The file path is correct in my system, but when I ran your 'system' version the error was more explicit stating that the directory wasn't found so that is definitely the problem. However, the file path is correct and even placing the xfoil.exe in the same directory as the program and using a local path leads to the file still not being found. Could it be possible that CodeBlocks does not have the permissions to access other files?
Possibly, but I have to say I know very little about Windows file permissions. You could try running the exe from cmd or cygwin's shell.
EDIT: It works just fine from Code::Blocks for me, no clue what's going on on your end. If I change the path to xfoil.exe to something that is wrong, it gives me that same "No such file or directory" message. I can't really find anything on system
regarding this kind of behavior either. Either way, seems to me like this isn't an issue with the library, so much as with your configuration.
FWIW, here's how I got everything working. You could try following these steps on a clean install (e.g. on a VM), just to see what's the difference with your current configuration:
CXXfoil/tests
.C:\cygwin64\bin
. Change C compiler
, C++ compiler
and Linker for dynamic libs
to gcc.exe
,g++.exe
and g++.exe
respectively.Can you spot anything that might be different about your setup? In any case, have a go at following these steps and see if it works that way. Might be that something, somehow went wrong when you set up your build system or something.
So I figured out how to access xfoil.exe. Firstly, I was using a shortcut to the real application which it system() didn't like. Secondly, I need to have the program and the xfoil executable in Cygwin's home directory for it to be able to find the xfoil regardless if I am using an absolute path. In this directory relative paths work as well. However, upon generating a very simple makefile to test out the wrapper, the resulting executable doesn't run but for a split second. Running the program through CodeBlocks just says that the program cannot be found, but I have had success opening xfoil myself with system() now that I am in the correct directory. I don't get any build errors so I assume my makefile is operating well but just so you have it, it is linked below.
Makefile: https://pastebin.com/xvuRSyUL
P.S upon generating the makefile it gives me an error saying that the variable child_status is unused in xfoil_runner.cc.
P.P.S just saw your edits and I really don't see anything different with my setup. I have tried re-downloading Cygwin a few times with no change and I have all the CodeBlocks compiler settings as well.
I'll have a closer look at your Makefile tomorrow (it's quite late over here right now), however, one thing you could try is to use cmake
instead of make
. Nobody really writes Makefiles manually anymore. If you want to try your hand at this, just place this CMakeLists.txt
file in your project directory: https://pastebin.com/SAzMEF98
Provided that the cxxfoil library is in its own CXXfoil folder in your project root, i.e. as if you cloned the repo directly into your project root. The directory structure should look like this:
. ├── CMakeLists.txt ├── CXXfoil └── main.cc
Then, from your project root, enter the following commends:
mkdir build && cd build
cmake .. -G "Unix Makefiles"
make
This will create a file test_cxxfoil.exe
under build
. If it complains about missing dll's (e.g. cygwin1.dll), you can place those dll's (located at C:\cygwin64\bin
) into your C:\Windows
directory, or alternatively add their directory to your %PATH%.
Thanks for the info! When I run your sample CMakelists.txt it can't seem to find the header files (specifically xfoil_config.h but I suspect that that is just the first one that it tried and failed to find. I have the directory set up as you indicated above.
EDIT: I got it working by including the path to the header in main (CXXfoil/...). Now when running the executable it still immediately crashes. From some testing I think that is from the program's inability to open xfoil.exe. As mentioned previously, I can open the executable in the same directory with a simple system(). I don't know why the wrapper can't access the file as well.
EDIT 2: I went ahead and retried the CodeBlocks to see if I could get it to work witht the same results as above running the generated executable However, when running in the application I get the message that it returned 0 (0X0)
Hi, it's Matthew. Thank you again for updating your wrapper. Unfortunately, the new version has a lot of errors on my side. These seem to be general syntax (at least from what CodeBlocks outputs). Here is the error readout: https://pastebin.com/dM12cv0A
I am running Windows 10, with CodeBlocks 17.12 and Cygwin version 2.11.2. The code does not run currently, but my XFOIL version is 6.99.
Thanks, Matthew