I've been trying to follow lazy foo's productions tutorial on sdl2 and I keep on running into the same issue. I made a template that links to the correct files and all and it worked for a while. But now when I create a project and include iostream for example, it tells me #using need c++/cli mode enabled.
So I then tried enabling it in the project settings but then it gave another error : "Cannot open metadata file iostream"
I tried :
Rebuilding the project and solution
Cleaning the project and solution
I read this question and its answers : Visual studio - getting error "Metadata file 'XYZ' could not be found" after edit continue
Tried this too : IntelliSense: "#using" requires C++/CLI to be enabled
All of the above did not work
Don't confuse #include, using and #using.
#using is used to import class libraries in C++/CLI, which is something you won't ever need unless you work with .NET libraries (but then usually you are better off just using C#, unless you are writing interop code).
#include is for including header files, which is what you normally do in "regular" C++. <iostream> is a regular standard library header, so you need #include (as in #include <iostream>).
using instead is used to bring names in the current scope (either the whole content of a namespace - as in the dreaded using namespace std;) or single names (as in using std::cout;). From C++11 it's also used to enable constructors inheritance and to create type aliases, but for the moment I don't think you need to worry about these uses.
But most importantly: please take the time to first learn the basics of the language from reputable sources before trying random stuff. All this #using mess wouldn't have arisen if you even just looked first at the classic hello would example you can find everywhere on the Internet.
Related
Context:
I am trying to run the code for a thin-plate spline provided by Jarno Elonen at http://elonen.iki.fi/code/tpsdemo/. It requires the installation of OpenGL + GLUT and the Boost uBlas library. I have downloaded the code, but I have been unable to run it because the compiler can't locate the GLUT and Boost files.
I'm hoping that someone can get the code on the website to run (and not just address the immediate trouble I'm facing), and tell me the exact steps to follow to get it to run. (I don't mind if you dumb it down completely, I'm a beginner :) )
What I have done so far:
Downloaded and extracted tpsdemo-1.2.tar.gz from the website above
Downloaded FreeGLUT (because various online forums told me I should be doing this as GLUT itself is outdated...): Freeglut 3.0.0 from freeglut.sourceforge.net/index.php#download.
Downloaded Boost: boost_1_61_0.zip from www.boost.org/users/history/version_1_61_0.html.
I don't know what to do from here... where should I put these files so that the code from tpsdemo-1.2 can access them? I have tried putting it in the same directory, but this seems to require using #include "filename" with quotation marks instead of the #include <filename> with angle brackets which is in the provided code. If I do alter it like this, then it seems like I will have to change all include statements in GLUT and Boost (which currently use angle brackets) which is not a small task. (I don't really want to be modifying too much code...) What's the correct way to do this? I have tried using the -Idir tag while compiling but this runs into other problems, although I don't know if this problem is to do with GLUT/Boost (which is why I'd like to see if anyone else can get the code to run!)
wedge brackets in a#include are for denoting files that exist on a system or framework level. As such you never get them there by moving them into the "right" place, but instead you specify which directories are to be considered "system" or "framework" level. The exact method in the end is depending on the compiler used, but all major compilers out there understand the -I${PATH_TO_INCLUDE_DIRECTORY command line option notation. -I… may be specified multiple times to specify multiple directories.
It is a good style to use wedge bracketed includes exclusively for headers that are 3rd party to a project and/or for headers that form the framework of a project. For headers that belong to modules of a project itself quotation marks should be used.
So a few hours ago I started learning c++ in codelite but I was getting frustated with, so I just got codeblocks and imported the project. But now whenever I try to compile it returns:
fatal error: imports.h: No such file or directory
This is my project hierarchy in codeblocks:
And this is what the project folder looks like:
What am I doing wrong?
I know this is years later, but I've recently seen students following what I deem is frankly bad advice such as what is given above. For those learning c++ this functionality is NOT for you. To add headers you should simply check that you are using double quotes, instead of angled brackets i.e.
#include "myheader.h"
and NOT
#include <myheader.h>
Angled brackets are meant for libraries (informally) and adding a simple header file for you basic classes does not require you to change default search directories. The problem comes when someone else tries to run your code (assuming you're doing this for uni) and their IDE isn't setup to search for a "library" (your header) where it shouldn't be. Double quotes tells the compiler the files exist in your current relative directory. This way you can keep your main, headers and header implementation in one directory. Fiddling with your IDE should only be done when necessary. KISS
You have to tell Codeblocks where to find the header files that you include. Try adding the full path to your '/Headers' in the include directories of codeblocks
Goto 'Codeblocks menu > Settings > Compiler > Search directories > Add'.
EDIT: Since your issue, however, is quite irrelevant to learning the C++ language itself, I suggest that you start with simpler programs, then move on to more complex ones. That, of course, unless you have previous experience with other programming languages
Since I haven't found any Makro for
#define 'hostname of device where compiler is located' // which is unique and not to be copied !
I have now successfully used and included
#include "myCompileEnv.h"
as a workaround with the comments above, which is located more central - above the project directories in CodeBlocks.
I have a Windows C++ project which compiles with the /clr switch.
To use the Form object I had to write
#using <System.Windows.Forms.dll>
using namespace System::Windows::Forms;
and then I could declare and use the Form object.
now I'd like to use Some DevExpress components. So I went into the properties of the project and added a reference to DevExpress.XtraEditors library
then in my code wrote
#using <DevExpress.XtraEditors.v14.1.dll>
but it tells me it cannot find such a lib, so I wrote
#using <C:\Program Files (x86)\DevExpress 14.1\Components\Bin\Framework\DevExpress.XtraEditors.v14.1.dll>
for which I don't get an error, but I don't like to write full path.
Anyhow, after this I added
using namespace DevExpress::XtraEditors;
but when trying to declare a variable of type XtraForm
extern gcroot<XtraForm^> form;;
it tells me it doesn't know about such data type.
What am I doing wrong here?
What is the correct way to reference a 3rd party library to a mixed C++ project?
Any good articles are highly appreciated.
thx
I am trying to compile a Visual Studio / C++ code snippet I have found on the internet containing the function:
Marshal::SizeOf()
When compiling the snippet, I get the error message:
error C2653: 'Marshal' : is not a class or namespace name
so I think I need to include a header file with the definition of this namespace or class, and the SizeOf() function.
When I look up Marshal::SizeOf C++ in Google I find this help page, however on this page there is no information regarding which header file must be included in order to use this function.
Is there a documentation page where one can look up all .NET classes and functions and easily find the C++ header file that must be included in order to use them?
You need to understand what C++/CLI is. It is a proprietary extension to C++ by Microsoft to make the interfacing between native and managed code (i.e. .Net) easy.
Marshal is not a C++ class, it's a C++/CLI class. As such, there's no header to include. It's #import you are looking for.
I have been trying to add MobileSynth to my application for some time now and I am only running into errors.
I have followed the steps here which explain how to add a project into another one.
When I compile, both projects are compiled correctly without errors, but the moment I try import the code into my objective C source code I get a large number of errors.
This is a screenshot of the errors.
Im sure there are more errors than these as there seems to be something wrong with the dependencies.
I also approved Xcodes recommendation to convert the project 2 (containing the objective C viewcontrollers with .mm extensions and the .cpp files) from an old 3.something version to the version 4 project type, and made the snapshot. Didnt seem to change anything.
I am not sure how to solve these issues. I would really appreciate any help.
Use using namespace instead of namespace.
You're aware that files that use C++ need the .mm extension. You also need to consider import dependencies. Since this header contains C++, any other file that imports it will also need to have the .mm extension. I'm almost positive that's what's happening to you.
I generally try to keep C++ quarantined to the implementation files for this very reason.
Also, for clarification on previous advice:
// Correct
namespace synth { class something; }
// Incorrect
using namespace synth { class something; }
// Optional
namespace synth { class something; }
using namespace synth;