I am trying to use Eclipse CDT with the Cygwin GCC toolchain in order to read in some images using png++. I have installed the png++ headers (I tried both 0.2.5 and 0.2.7) in my Cygwin, and it compiles fine using the external builder settings with make, but for some reason the editor underlines "image" from png::image in the very simple code:
#include <png++/png.hpp>
int main( int argc, char* argv[]){
png::image<png::gray_pixel> t(128,128);
return 1;
}
And gives the error:
Invalid template arguments.
I looked around a bit for this error, and it seems for other people it was caused by not having GCC set to use C++11 (such as Invalid template arguments on map std::map< std::string, Stock*> &stocks), but I do not think that is an issue with me, since I have my "CDT GCC Built-in Compiler Settings Cygwin" provider command set to:
${COMMAND} ${FLAGS} -E -P -v -dD -std=c++11 "${INPUTS}"
And the line std::normal_distribution<double> distribution(5.0,2.0); does not give an error.
I can remove the error underline by turning off "Invalid template argument" under the project properties -> C/C++ General -> Code Analysis, but the problem is deeper than that, as none of the auto-completes will work for the object of type png::image, and if I try and use it in a function, for example:
void pngTest(png::image<png::gray_pixel> im, int other) {}
it gives the error: Invalid arguments ' Candidates are: void pngTest(?, int) '
So it seems it does not resolve the type at all. What might be causing this?
Turns out this was not actually a bug with Eclipse parsing, but an incompatibility with Cygwin style symlinks. In png++'s png.hpp and types.hpp it includes png.h from libpng, but in Cygwin png.h (in /usr/include) is a Cygwin style symlink to the current libpng (in my case the file contained the text: !<symlink>libpng16/png.h).
So Eclipse could not resolve this include, even though Cygwin's GCC could, and it was making the typedefs in types.hpp not resolve correctly. This is why I was getting an invalid template arguments error in eclipse, png::gray_pixel was not a valid type. I noticed this when I put <int> instead and it no longer gave an error. So that was the problem.
I changed the include paths from png.h to libpng16/png.h in both png.hpp and types.hpp
and now everything in eclipse is resolving correctly after a right click on the project -> index -> rebuild. Alternatively you could symlink png.h, pngconf.h, and pnglibconf.h in /usr/include to the appropriate libpng subfolder using the windows mklink command and remove the Cygwin style symlinks.
If anyone knows a way for Eclipse to work seamlessly with Cygwin symlinks then post here and I will accept that as the answer, since obviously that is a little better than this hacky fix.
Thank you guys for the comments, but it seems thankfully that this time it was not an Eclipse issue.
Related
I am using Eclipse CDT (2018-12 (4.10.0)) for a C++ project (cross compiling with gcc 4.9.2).
In the following code the indexer got a problem with f(std::chrono::seconds(33));
#include <chrono>
void f(std::chrono::milliseconds) {
}
int main() {
f(std::chrono::seconds(33));
}
The diagnostic says
Invalid arguments
Candidates are
void f(std::chrono::duration>)
The compiler processes the file without any problem though.
If I create a simple x86_64 project the indexer is happy.
What setting is incorrect in my project? Apparently both compilers can do the job and the indexer, too.
Under C/C++ General->Preprocessor Include Paths, Macros etc.->Providers->CDT GCC Built-In Compiler Settings->Command to get the compiler specs
I use the following command:
arm-v7a-linux-gnueabihf-g++ ${FLAGS} -E -P -v -std=c++11 -dD "${INPUTS}"
Is there any setting I can change to make the indexer happy?
I try to get tests generated by the cxxtest framework working under a MinGW environment managed by mysys2. The tool generates C++ files with absolute paths. However, gcc seems to be unable to resolve this absolute paths.
Here is a minimal example to demonstrate the problem:
// file1.h
#include <iostream>
inline void hallo() { std::cout << "Hallo\n"; }
// main.cpp
#include "/home/phil/example/file1.h"
int main()
{
hallo();
return 0;
}
The file exists (at least the msys2 shell resolves the path):
$ ls /home/phil/example/file1.h
/home/phil/example/file1.h
... but calling g++ results in this error:
$ g++ main.cpp
main.cpp:1:38: fatal error: /home/phil/example/file1.h: No such file or directory
#include "/home/phil/example/file1.h"
^
compilation terminated.
Same error with clang.
Under a full Linux environment, the example works. It also works if I replace the absolute path by a relative one (#include "file1.h").
So, I assume the problem lies in the layer over Windows that is responsible to resolve paths. Not sure whether I should report it as a bug to the msys2 project, or whether it is a known problem. If it is a known problem, are there any workarounds (like setting -I options)?
(If possible, I would like to avoid replace the absolute paths, as they are in generated code by the cxxtest framework. Technically, running a postprocessing step on the generated files would be possible but seems like a hack in the long run.)
Since you are running compilers that use MinGW-w64 as their runtime environment, they don't recognize POSIX-style paths like that. I think they actually interpret the root directory "/" to be "C:\". Other than that, they would only recognize native Windows-style paths.
I recommend that you pass the argument -I/home/phil/example to your compiler from some program running in the msys-2.0.dll POSIX emulation runtime environment (e.g. /usr/bin/bash or /usr/bin/make). The msys-2.0.dll runtime will then convert that argument to use a native Windows path so the compiler can understand it, and statements like #include <file1.h> will work. Alternatively, you might try putting a Windows-style path in your source code, e.g. the path should start with C:\.
Note however that having absolute paths in source code or build scripts is a bad idea since it makes it harder to build the code on a different computer. You could consider using environment variables or relative paths.
Try using the MinGW compiler that Cygwin provides as a package. (In other words, forget the MSYS environment; work under Cygwin, but build the code as before, in the MinGW style.)
Then you should be able to have include references /home/phil; it will just resolve to C:\Cygwin\home\phil or wherever your Cygwin root is.
Actually, it might be possible under MSYS also (which, after all, is just the descendant of an old for of Cygwin). You just have to figure out what /home/phil is referring to, create that tree and work under there.
I am attempting to setup SDL2 for C++ with Eclipse on Windows 7.
In order to do so, I am following the tutorial in this link, which states that I must first install MinGW. So I follow the link provided in order to setup MinGW. I follow all the steps without issue. I then open Eclipse and attempt to build a simple hello world program:
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!" << endl;
return 0;
}
To my surprise, this code doesn't build, with 6 errors.
I then proceed to simplify the program further:
int main()
{
return 0;
}
This also does not compile. There are two errors:
Program "g++" not found in PATH
Program "gcc" not found in PATH
Here is a screenshot.
However, my path does contain "C:\mingw\bin". I have also tried changing this to "C:\mingw". Looking inside "C:\mingw\bin", I find gcc and g++:
In addition, compiling a test program using the command line (g++ Test.cpp -o Test) works just fine, as does "g++ -v".
I have been searching the web for hours, and can't seem to find an answer as to why Eclipse can't seem to compile anything with MinGW. Questions I have looked at on SO (which haven't been able to fix my issue) include:
Eclipse mingw binary not found
Eclipse not finding c std libraries
g++ not found in path
Eclipse C++ : "Program g++ not found in PATH"
Program g++ not found in path
Program g++ not found in path C++ [duplicate]
Eclipse CDT (Juno) in Win7: Cannot find g++ in PATH, iostream unresolved and other fun stuff
Additional info:
Window > Preferences > C/C++ > Build > Settings > "CDT GCC Built-in Complier Settings MinGW [Shared]" : Toolchain MinGW GCC is not detected on this system.
I have also reinstalled Eclipse to no avail.
I realize that this may be a duplicate question of some that I have linked, but the information in previous questions have not been able to fix my problem, and I fear that adding a comment to an old question may not result in an answer.
Please request additional information as needed.
You need to set the environment for the c/c++ builder.
First you need to install the GNU tool-chain, you can choose either MinGW or Cygwin. You can see the steps here. I used MinGW.
Go to Window->Preferences->C/C++->Build->Environment and add a new variable, name it whatever you want for example a named it "MINGW", now paste the binaries directory of MinGW which is by default C:\MinGW\bin, you should have something like this:
Now when you create a new project you just have to select the MinGW tool-chain:
Hope that helps.
It appears as though I have fixed the problem for the moment.
In case others encounter the same issue:
Project > Properties > C/C++ Build > Settings > MinGW C++ Linker > Command changed from "g++" to "C:\mingw\bin\g++".
I am running Cygwin on windows 8, attempting to compile the source code for a game I would like to mod. Unfortunately I am running into some errors while building involving the fileno function. After doing some googling It seems like the problem might have to do with c++11 support (I'm not really sure what this means). Most of the solutions people have found involve adding some option like -std=c++0x or -std=c++11 when compiling, but my attempts to add the options into the makefile have been unsuccessful, and I don't know if that's whats causing the problem anyways. I'll include the code snippet that's throwing the error and a link to the makefile as it is quite large. Any advice you could give me would be great.
code that throws error:
time_t file_modtime(FILE *f)
{
struct stat filestat;
if (fstat(fileno(f), &filestat))
return 0;
return filestat.st_mtime;
}
Link to Makefile
it is being hosted on github
EDIT: After getting some advice I poked around the makefile and found five instances where the -std option was used, playing around with them hasn't changed anything. Is the problem with my Cygwin configuration? I installed the packages I was told I would need in the installation guide for the game I am building.
Changing the -std=c*** in your makefile to -std=gnu++0x should fix your problem.
If you don't know what c++11 is you're most likely not using it anyway.
Also if you need c++11 support you can also do: -std=gnu++11 instead of -std=gnu++0x
For windows...
fileno() is deprecated: https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/posix-fileno?view=vs-2017
use _fileno() instead: https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/fileno?view=vs-2017
I have set up MinGW and Eclipse with CDT for C++ developing on Windows. Everything works great until I #include <windows.h>. As soon as I do that, I get the linker error message c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: final link failed: Invalid argument whereby the path at the beginning resolves to C:/MinGW/mingw32/bin/ld.exe.
I have no idea what the error message tries to tell me... so please help me to decrypt it.
Since I actually don't agree to Lol4t0's opinion that this is too localized here is the ugly answer: Reinstalling G++ solved the problem.
I think the problem also could have been that I maybe forgot to install one of the parts listed here (where I got it from) for the first time... but now I recognize the link is completely deprecated (2005). So one should use another anyway.
Perhaps you are missing one of the linking parameters on the command line.
E.g., you might want to add the -lgdi32 -lkernel32 -luser32 if you use any of WinAPI functions declared in <windows.h>
Since you are getting errors in Eclipse, add these libraries (gdi32, kernel32, user32) here:
Project Proprerties -> C/C++ build -> Settings -> GCC Linker -> Libraries -> "add the library"
(this is taken from eclipse cdt command line input)