How can i get C++ coding in eclipse to act like coding in java?
In java, i can nicely add external jar files and the code assist can nicely suggest methods or suggest adding unimplemented methods for interfaces.
But in C++ mode, it doesn't seem to work when i include external header files. What else should i try?
Eclipse CDT itself does not come with any compilers/libraries therefore you need to select and install a toolchain. There are a few options for this
Visual Studio (cl)
MinGW (g++)
Cygwin (g++)
Note, you can get VS Express for free and if you are a student can even get the professional version from Dreamspark
Once you have installed any of these you can select them as the toolchain for your C/C++ projects, this will enable you to build your projects nicely from within eclipse.
Also, you may need to point eclipse to the library files used by your compiler, for instance I use the VS2010 toolchain under Eclipse CDT so I must add
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include"
to the include directories in build settings.
Edit: Sorry if it wasn't clear, once you've done this code completion should work for your C/C++ projects.
Related
I'm trying to setup local Windows eclipse for remote Linux development. I have encountered problem with eclipse not recognizing simple 'printf()' statement from <stdio.h>. I didn't find any helpful resources ATM to solve this problem, so wondering if you could help me with this.
Header files used from: Visual Studio Build Tools 2022, specifically I'm including this folder for stdio.h file: 'C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041\ucrt'
GCC C++ Compiler as: "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\Llvm\bin\clang.exe"
Eclipse IDE still highlights this as 'Function cannot be resolved':
I am not sure, but looks like 'printf' function is available at 'stdio.h':
Update:
Eclipse version used:
Using command line build is working as expected:
Program runs as expected:
So the questions are:
What needs to be done so eclipse would recognize 'printf'? e.g. Change MS Win Kits for another compiler header files? Or my eclipse configs are wrong?
If it is not possible for eclipse to recognize 'printf', is there an option to ignore all warnings on 'printf' (not highlight them)?
Let me know would you need anymore details from my side.
After some investigation I think 'clang' is not compatible with eclipse & it's way easier to install & use 'cygwin' for such purposes.
Some references:
https://www.eclipse.org/forums/index.php/t/1092409/
https://www.eclipse.org/forums/index.php/t/1102938/
I kept hearing Connector/C++ should run on the compiler that it was compiled on, and one document says that's Visual C++ 2013. I'm using Visual C++ 2017 and I'm not downgrading. The document may have been old, so I'm curious if anyone has had any success and what you did to make it work.
Yes it will definately work. You just have to add include path and library path of MySQL to your VC++ directories ( Project -> Properties -> VC++ directories).
Now that you have included path you can directly use mysql.h header to call mysql c functions.
No, for C++ you have to find a version that got compiled with the same settings as your project. You can switch to using the C version of the connector which does not suffer from C++'s lack of ABI. You can find the C tutorial here.
If you would like to try your luck with C++, then make sure the build settings of the library you use match your project:
version of Visual Studio
version of stl
exception handling
vtable layout
stack and stack frame padding
Bitness (32 vs 64)
Iterator debug level
runtime linkage (MT vs MD)
build configuration (Debug vs Release)
characterset (multibyte vs unicode)
Fortunately the linker will check the compiler version _MSC_VER and will not allow you to link to the older library.
Is it possible to change the restrib file to msvcr100 so other computers can run the program without having problems with the .dll file? If so how do i get that?
I do compile the program and other people can't use it because of the missing msvcr120.dll file. So it would be great if i could change that somehow.
Is it possible to install the Plattformtoolset without a older Visualstudio version?
You have a few choices:
Install VS2010 on the machine, and set the Platform Toolset option to v100.
Install the Windows SDK v7.0A from here, which SHOULD / CAN add a new option to your Platform Toolset menu in VS2013. Getting this to work can be quite fiddly though. (It's rarely worked for me right out of the box). Note if you use MFC in your application, this option isn't any good for you - MFC libraries are not included with this SDK.
Get your users to install the Microsoft VS 2013 C++ Redistributable Package from here, and carry on regardless.
Statically link to the VS2013 runtimes, instead of using dynamic linking to the runtime DLLs. You can set this in the IDE through project settings under C/C++ > Code Generation > RunTime Library > Multi-threaded (/MT) or (/MTd). All the needed code will be compiled into your app, which will make the files bigger, but will avoid the issues you mention.
In Project > Properties > General, there is a setting called Platform toolset. You can use that to change the version of the build toolchain used.
One thing to consider in regards to changing the platform toolset: it changes the compiler, so C++ features newer than Visual Studio 2010 will not compile. It also requires the other version to be installed.
The best way to handle this would be to give them the Visual C++ Redistributable for Visual Studio 2013.
You could either have them do it themselves, or make an installer.
I want to use Notepad and invoke the compiler and linker from the command prompt.
No IDE no make , nmake or anything like similar because I want to know the exact syntax required to do the following:
1. create a static library
2. create a dll
Yes, I have browsed the MSDN site but the examples I saw assume one is using the IDE which does a lot of setup behind the scenes
Pls Note: I know how to compile executables using cl also setting up the env using vcvarsall.bat. My question is about compiling static libraries and dlls.
I am using Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86.
Suggestions on to use some other compiler ( gcc, mingw, intel etc.) will not be helpful at the moment.
The C++ compiler is named cl. The compiler options are well-documented on MSDN. The linker is named link. The linker options are also well-documented on MSDN.
You'll need to run vcvarsall.bat to be able to build with the Visual C++ toolchain; this batch file sets up all the required environment variables and such. If you've installed Visual Studio, you should have a shortcut on your Start Menu entitled "Visual Studio Command Prompt." This shortcut will get you a command prompt and run that batch file.
For DLLs, pass the /c flag to cl.exe (which compiles but doesn't link), and pass the /DLL flag to link.exe. Instead of making an executable, it makes a DLL.
For static libraries, use the lib.exe program.
There are multiple approaches, all of which are handily documented in one place:
Visual C++ Concepts: Building a C/C++ Program
Building on the Command Line
Note that the build system completely changed between VC++ 2008 (which you're using) and VC++ 2010 (which is the current release).
A couple of minor things to add.
Personally I wouldn't use Windows batch files.
I would use nmake http://msdn.microsoft.com/en-us/library/dd9y37ha(v=vs.71).aspx building outside of visual studio is nmake's day job and that's the standard way to build visual studio projects for release say on a build machine, rather than in a development environment.
The other thing in nmake's favour is that if cross-platform is important to you then cmake ( http://www.cmake.org/ ) is a brilliant tool for dynamically creating Windows nmake files and non-Windows make files and it comes with ctest for running your unittests and selftests.
Advert over.
As may be known by many, the Express versions of Visual Studio 2008 don't include support for MFC and a few other packages required to compile a lot of windows programs.
So, here's my problem:
I have the full version of Visual Studio 2005. I've been using this to compile a project that a friend of mine was working on, so that I could test it out for him and continue to track bugs and things. Recently, he upgraded that project to VS 2008, which I don't have. So, I downloaded the express version in the hopes that I could simply compile with that, but no luck, it complains about headers missing left and right.
It seems to me that since I already have the full version of VS 2005, I'm bound to have at least some (perhaps older) version of the files in question that his project needs to compile against.
Is there a way I can convince VS 2008 to also look in 2005's directories for include files and library files to compile against?
Furthermore, is this a bad idea? I would really prefer not to go out and purchase VS 2008 full, as I'll never use it myself. (2005 does the job fine for me at the moment, and I tend to prefer GCC anyway.)
Thanks
You can use the VC++ compiler directly from the command line, or just create a new project w/ the source in Visual Studio 2005. Unless he is using some functionality provided in the new versions of MFC/ATL in 2008/2008sp1, you should be able to compile the project just fine.
See ("Create Project from Existing Source") in Visual Studio 2005. It is unfortunate that they don't include these libraries with the Express Editions.
Use the vcvars*.bat script(s) from Visual Studio 2005. See this blogpost from VC++ Blog to see how. You will use the old compilers, but the build system from Visual Studio 2008.
You can go into Tools>Options>Projects and Solutions>VC++ Directories
and alter the Include, Library, and Source (and Reference maybe?) folders to use VC++ 2005's folders.
I'd guess you just replace $(VCInstallDir) with a hardcoded VS 2005 path. I'd record the original values before doing this.
However, have you just tried using the OLD 2005 sln and vcproj files? Keep using 2005 on your end and 2008 on his. Keep two sets of these files for each IDE. Any issues are going to be with the library mismatch - which you're not avoiding by using 2008's tools with 2005's libraries.
The simple way to deal with this would be to revert the solution and project files back to their visual studio 2005 state from source control(you are using source control right?). At this point you can compile the project as long as your friend does not use any of the mfc 9 only functions.
The first thing I would try is loading this up in VS 2005 by just modifying the version of the .sln and the .vcproj files. In the .vcproj change the version from 9.00 to 8.00 and in the .sln change the format version from 10.00 to 9.00.
If you don't have fancy stuff in the project you have a high chance of just being able to use it like this. Also this would avoid having to update 2 project and solution files.
On this website it is shown how MFC code can be compiled with the Visual Studio Express versions:
link
Just for the record, I've done that(by modifying the include directories and library directories from inside the IDE) and it's working pretty well, I have MFC, ATL, everything.
I've found this explanation. http://www.codeproject.com/Articles/30439/How-to-compile-MFC-code-in-Visual-C-Express