I've been developing a lot in Java lately but I've been asked to look at switching one of my projects to C++ and I'm having a bit of trouble setting up the includes. Unfortunately the extent of my C++ knowledge is a couple of academic projects I did in college.
I have created a project in NetBeans and I'm trying to add in some headers from an external library (pugixml). I have
#include "pugixml.hpp"
at the top of the file I intend to use it in. The problem is that when I compile I get
main.cpp:9:23: pugixml.hpp: No such file or directory
which seems odd to me seeing as the IDE definitely knows where the file is. Code completion on classes from inside the library works and holding control and mousing over the file name shows me the correct directory where the file lives. How do I convince the compiler to include this directory?
I know this really feels like something that should be easy to Google, but I haven't had any luck.
if you are using a makefile on linux:
check your makefile and add the -I Path_to_your_pugixml_hearders in the option of its compilation recipe.
or, add your path to the environment variable $CPLUS_INCLUDE_PATH. for example, in bash
export CPLUS_INCLUDE_PATH=Path_to_your_pugixml_hearder:$CPLUS_INCLUDE_PATH
Related
I've been trying to get this to work for a while but cant figure it out for the life of me.
Here's my situation right now:
I have a Visual Studio project (and solution) up and running, and would like to modify it as little as possible. I now feel the need to use GLOP Linear solver within my project, and was wondering how I'd go about doing this.
The code that I've written that uses GLOP works perfectly as a standalone .cpp file :
[ this .cpp file is placed in the same directory as the resources for GLOP, and compiles and runs perfectly after creating and using the make command as mentioned here https://developers.google.com/optimization/introduction/cpp
]
I would now like include this code in my project, and run it as a part of my project rather than as standalone code. As I'm currently using MSVS 2017, I was wondering how I'd go about doing this as the current tricks I've used (copying and pasting all the resources for GLOP in the project folder, among other things) don't seem to be working and my error list keeps growing, and using the make commands is obviously not an option as the code needs to embedded amongst other code.
Please explain to me like I'm five years old - what files are supposed to go where, what linkages am I supposed to perform and what other.
I suppose you have already downloaded and extracted the binary archive:
or-tools_VisualStudio2017-64bit_v6.8.5452.zip
When running the make rcc command to build a C++ example, you should have spotted the needed flags to use in your project.
First you need to configure your project to add the include directory:
Configuration Properties>>VC++ Directories>>Include Directories
Then you must add some preprocessor flags e.g. -DUSE_GLOP
note: you can find here what we use in the Makefile:
Configuration Properties>>C/C++>>Preprocessor>>Preprocessor Definitions
Then add the static library libortools.lib to your linker:
Configuration Properties>>Linker>>Input
Note: Images come from various sites on the internet please adapt it.
I am coming from KDE to XFCE and hence arrive from KDevelop at Geany. I have no plans of using Geany for any compilation stuff, prefering to write my own CMakeLists.txt files. However, what I loved about KDevelop and dearly would have again:
In KDevelop I could "attach" an include-directory to a c++ file meaning that code autocompletion would look for #included headers within that directory and use its content.
For example it was possible to "attach" something like /usr/share/myIncludes/
containing "my_foo.h". Then in the source code of my program I would
#include "my_foo.h"
and henceforth auto-completion would kick in using the contents of "my_foo.h".
I find this surprisingly hard to google. Is there even a feature like that in Geany, and if so, how would one use it?
My Geany is a simple install (geany and geany-common) on a clean (no non-free stuff) Debian System.
Geany is not supporting dynamic parsing of header files due to the performances and resources impact it would have.
However, you can generate a tag file from your headers as described inside manual or maybe use a plugin like geanyctags or projectorganizer (recently rename from gproject) which could help you there
Also you can find tag-files inside the wiki which you can import via the Tools-menu.
The situation is the following: I have the source code of one programm (lets call it programA) (written in C and C++), as well as the CMakeLists.txt and CTestConfig.cmake files. I already installed programA using CMake's graphical user interface and, as it is obvious, it worked. It created the .exe file (I'm working on Windows 7 OS).
The problem is that, right now, I've been asked to edit the program (and so, I must be able to edit the code and degugging it as changes are made). I also need to compile it but not in .exe anymore but in .dll so I can add it to a website we have.
I've read in forums that CMake can compile programA into a .dll if I need to, but as I would need to make some changes I consider that CMake debugging is not as useful and easy as using entirely VS. From the little I know from CMake language, the CMakeLists.txt is mainly used to check the OS of the user as well as adding some libraries in case they are not found.
I have to admit I have no idea in programming CMake directives, as I have been working with ASP.NET, C, C++ and C# mostly. Then, my idea is to try to work only in visual studio 2010 instead of using cmake as well, so once I have the program 'adapted' to VS and can be compiled just using VS, I'm ready to start my job. So the question I have is how can I perform the same task CMake did just using Visual Studio (Is there any way of implementing CMake directives in VS?), can VS compile by receiving as an argument something similar to that CMake.txt file (though it needs to be translated into another language)?
To skip the use of CMake I tried to copy the source code into a new project in VS. However as it does not use the CMake directives when compiling, it gives several errors, most of them related to the fact that some headers.h can't be found (cause they might be in a subfolder). And there are so many subfolders to add the paths to the predefined directories of search that it would take ages.
I'm sorry I can't be more precise in my explanation. I'm good at programming little projects on my own, but it's the first time I have to work on other's programm. Please don't hesitate to ask if anything was not properly understood
I would appreciate a lot any suggestion / advice /guidance you can give.
To make a dll, use add_library command and the SHARED keyword
add_library(mylib SHARED ${files})
this is easy with CMake, don't go back in visual that will be harder at the end
The Good News
Fortunately, cmake can generate VS Projects automaticaly for you (this tutorial s specific for OpenTissue, but Steps 1 to 3 should be the same for you).
The [not so] Bad News
Depending on the complexity of the project, VS Projects automaticaly generated by cmake can get pretty nasty, to the point of illegibility. It will, for example, hard link any library dependencies using the specific paths of your machine, so the project will most certainly not be portable across setups. In any case, that's the intended bahavior, because the primary idea of supporting this generator is simply making it work, thus allowing users to easily compile projects using MSVC, so there's not much you can do here. Nonetheless, it should work in your machine and will certainly be a great starting point for you, just create a project yourself from scratch copying the relevant parts out of the automatic generated version.
I'm trying to compile a simple program that's already been written included in the Steinberg VST SDK.
The issue I'm having is my compiler can't find the file unless it has an absolute path. For some reason, the code is written in such a way that my compiler can't find where the file needed it.
For example:
In the file vstcomponentbase.h, located in C:\Users\180945\Documents\Programs\vstsdk352_25_09_2012_build_16\VST3 SDK\public.sdk\source\vst\
There is this line:
#include "pluginterfaces/base/ipluginbase.h"
ipluginbase.h is located in C:\Users\180945\Documents\Programs\vstsdk352_25_09_2012_build_16\VST3 SDK\plugininterfaces\base
Unless I change the line to
#include "C:\Users\180945\Documents\Programs\vstsdk352_25_09_2012_build_16\VST3 SDK\pluginterfaces\base\ipluginbase.h"
it won't work.
I'm using NetBeans as my IDE. I'd like for the files to automatically find where the files are supposed to be. It should work, as I'm using Steinberg's VST SDK, which has demonstrations and other bits of code that are supposed to work as given. There would be too many things to edit in something that should already work.
How would the compiler know where you have hidden those include files :) ? You need to add "C:\Users\180945\Documents\Programs\vstsdk352_25_09_2012_build_16\VST3 SDK" to the search path for include files in your compiler options. For gcc, the relevant option is -I, but many IDEs have a way of setting the include path in the project settings. Consult your IDE's manual.
I am trying to open an existing C++ open-source library in Xcode to publish it with my own modification/additions. The library is Tesseract-OCR, which does not include a .xcodeproj file.
Since Xcode can function as an IDE, is it possible to open a bunch of files as a single project in Xcode? Is there an easy way to produce an Xcode project?
There are several ways you could do it, depending on the level of IDE integration you want. There's no direct way of importing a Makefile-based project into Xcode. You can create a project that builds via the Makefile, but you wouldn't get many of the benefits of using an IDE, since the editor features such as word completion rely on Xcode being able to parse the files in the project. You will be able to use the debugger though. To do this, create a new project and add a custom target with a script build phase that just calls down to Makefile.
If however the project you're building compiles very easily, ie without requiring a lot of macros to be set up, include paths, etc, then it may be simple to just create an empty project and merely add all source files to it. I've used this method extensively for building boost libraries. If this is a configure && make type project then you will probably have to run the configure step first, and ensure any top level config.h files are included in the project.
If the project has a complex makefile then it is likely to be an involved task to create a useful Xcode project
I realise you asked explicitly for Xcode, but in case you were actually trying to solve the problem of "I have existing C++ code which builds and runs fine from the command line, and I'd like to code and debug it in an IDE, what should I do?" my firm recommendation would be to avoid Xcode and go for Eclipse.
The reason is that as far as I can tell, Xcode has no way of ingesting the command line build environment and effectively requires you to recreate the make process inside Xcode from scratch. Fine for tiny projects, but anything with more than a few source files and it quickly becomes painful. Whereas in Eclipse everything is built around Makefiles. So in my case I got to the "step through code with working code completion" in Eclipse a lot quicker vs. never in Xcode. This of course could be because I'm an Xcode noob, but my 2c.
To create an Xcode project from an existing cmake project, you can run cmake -G Xcode. It produces some folders and files apart from the project file, so it might be better to create a folder for it first. For example:
mkdir -p build/xcode
cd build/xcode
cmake -G Xcode ../..
Xcode is a useable IDE for library creation.
Of course a good first step is to see if the one source code will build on its own with configure scripts that are included.
If not, it becomes a question of how many libraries you need to link in.
There are resources online (or at least there used to be) for using Xcode (or perhaps it's forerunner Product builder) for porting Unix projects to Mac.
Good tutorial at: http://www.macresearch.org/tutorial-introducing-xcode-30-organizer
Another good reference is Darwin Ports.
As for doing this on your own. You can build c++ based libraries in XCode. People do that every day. You can even use one of the Xcode templates to get you started.
However, library dev requires more experience with Xcode then say a simple Cocoa "Hello World" app.
The remaining questions will be assuring that the source code's dependencies are already built into the Mac's SDK. (Don't hold your breath for linking to MFC)
It's a general question... So it's a general answer.
In Xcode8,there is "Xcode->file->add files to...",then choose your files.If you want to add several files at a time,press "Cmd" when you are choosing.