Integrate Octave with C++ in QtCreator IDE - c++

I am trying to do some DSP operations in C++ using Octave...I have been trying to integrate Octave with QtCreator 5.1 (MinGW compiler) with no success...I have done the following steps...
Downloaded Octave3.4.3_gcc4.5.2-install.exe and intsalled in C drive. I have added the address of the bin folder of octave to the environmental variable PATH
Set the INCLUDEPATH and LIBS according to the location of the header files and the libraries of the Octave directory.
This is the sample program I am trying to run .
The code builds successfully. However while running it hangs up. Debugging yeilds the following message.
I tried to create an executable using the command prompt of octave using the command mkoctfile --link-stand-alone octavetest.cpp -o octavetest. The executable created also hangs up with an error message.
If anyone can point out where exactly I am going wrong in the integrating process it would be realy helpful. Is there any other simple way to set up the environment to call Octave APIs from C++? I have almost checked on the internet forums including stack overflow with no luck...

Your gcc/libstdc++ version will likely be incompatible with the one octave got compiled with.
This compiler is as close as i got to the one used to build the current octave-binaries.
If you extract both archives and add their bin directories to your path variable, you should be able to build octave programs. Your linked sample builds for me.
You can also add the compiler in QtCreator. (Tools⇒Options⇒Build&Run)

I have done exactly the same thing on Windows. In my experience, you need to build Octave with exactly the same compiler that you're building your executable with. That's all there's to it. This really means you have to build Octave from sources. I have wasted a lot of time avoiding to build Octave, and in the end could never be sure that it'll be stable or not. Octave will build with VS 2012 with very minor tweaks.
Building Octave is really the only practical way to go, I think. The amount of time you spend setting up an Octave build will insignificant in the long run.

Related

Setting up OpenGL library on windows

I'm totally new to OpenGL, so I'm trying to compile my application at home. At my university I have everything settle by my professor in the lab and there I use Linux. At home I'm using windows 8 with visual studio 2013.
I'm trying to build a sphere in my app which contain the includes below:
#include <GL/glut.h>
#include <math.h>
#include <iostream>
So, since it contains Glut.h I went to http://www.opengl.org/resources/libraries/glut/glut_downloads.php#2 to download the library and make it rock, but I had some problems.
I thought the windows version would come compiled and it didn't. The dlls are not inside the package as I expected to link them in my project properties so I tryed to use CMake to compile the glut but it didn't work. CMake returns to me the following log:
CMake Error: Cannot open file for write: C:/Program Files/Glut 3.7 Build/CMakeCache.txt.tmp
CMake Error: The source directory "C:/Program Files/Glut 3.7/glut-3.7" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
CMake Error: : System Error: No such file or directory
CMake Error: Unable to open cache file for save. C:/Program Files/Glut 3.7 Build/CMakeCache.txt
CMake Error: : System Error: No such file or directory
It says that the folder doesn't contain the CMake file.
My download link to glut (supposed to be windows, not sure cos of the error) is this http://www.opengl.org/resources/libraries/glut/glut37.zip
Normally I programm java, which I dont have so many headaches to setup the IDE..so take it easy please and now I ask:
What am I missing to make my OpenGL code run?
Your teacher should help you at the first place.
I would like to inform you that GLUT library was abandoned since 1998. Last version is [3.7].But you are lucky!
"freeglut" is alternative to the OpenGL Utility Toolkit (GLUT) library.
Everything you need is here, I recommend reading it all.
And to help you out, here you can find Windows binaries, look for link called: "Download freeglut 2.8.1-1 for MSVC".
After download, you must link the library folder, include folder and copy freeglut.dll to you project folder (inside Debug or Release folder). You can find dll files inside a bin folder.
And after that, you can call #include "GL/glut.h" with no problems.
Good luck!
It doesn't compile with CMake. Open a Visual Studio command prompt and type nmake in the top level directory of the glut source code.
At my university I have everything settle by my professor in the lab and there I use Linux. At home I'm using windows 8 with visual studio 2013.
Then the very first thing you absolutely must do is heading to your GPU maker's website, download the newest drivers from there and install them. That is, because the drivers installed by default with Windows 8 lack proper OpenGL functionality.
So, since it contains Glut.h
You mean glut.h – file names are case sensitive on most operating systems (Windows not among them). So for portability reasons you should care to write them with the proper spelling.
I went to http://www.opengl.org/resources/libraries/glut/glut_downloads.php#2 to download the library
The old GLUT library isn't maintained for over a decade. Use an alternative implementation like FreeGLUT and use that.
so I tryed to use CMake to compile the glut but it didn't work.
Okay, here you got no technical problem, but a lack of understanding. Essentially your brain got what I call "IDE rot": All those sugar coating and clicky-pointy action of IDEs obscure what actually is going on when a program is built. You'll have to bit the bullet there and understand how the interaction between the build control generators the build system the compiler and the linker works.
CMake is a build control generator: In CMake you describe the build dependencies of your program sources. From that CMake generates the actual build information for the build system used (GNU make and GCC on Linux; NMake and MSVC++ compiler on Windows for example).
Of course for CMake to work there must be an appropriate CMake configuration present. And in the case of GLUT that's definitely not there (the last official release of GLUT predates the first release of CMake.
Now you should really wonder: Why did you call "cmake" in the first place? I bet, because you always did it so far, or you read it somewhere, without even trying to understand what's going on.
What you did was folloing a Cargo Cult – it somehow resembles the actual process, it looks like it from the outside, but it doesn't yield results. Feynman's speech later coined the term Cargo Cult Programming; interesting enough I was using that term (consistently with its definition, just due to being familiar with Feynman's speech) without knowing that other people already had coined it in exactly the same way. Such a often it happens, that people will come up independently with the same term for it.
Normally I programm Java, which I don't have so many headaches to setup the IDE
Well, that's your problem right there. You only know how to click around in an IDE. Even when programming Java, with an IDE, you should get intimately familiar with the actual build process: Java compiler, JAR file creating, and so on.
What am I missing to make my OpenGL code run?
I bet not very much. It's a lack of understanding how the build process for software works and is controlled. You'll have to bite the bullet and learn that first. And for that I suggest you install Linux or FreeBSD, or at least Cygwin on your computer.
Windows is not a very good system to learn those things, because its been built around clicky GUIs. That is not to say that Windows was a bad operating system. It's juat that you want to have something you can experiment with and quickly go through various iterations of build tool option switches. A GUI can't give you that.

How to compile WindRiver/Eclipse C++ projects from the command line?

I'm currently running a variant of Eclipse known as WindRiver, which is designed for embedded systems programming using C++ (specifically, I'm part of my high school's FIRST Robotics team).
I'm able to successfully compile and build the project from within Eclipse (Project > Build Project) but I'm looking for ways to automate this process by compiling by using the command line.
The project already contains a makefile and everything, so ideally I want to be able to just run that without making any manual changes. I pastebin'd the makefile in case its relevant.
Does anybody know where I can find more information on compiling C++ programs from the command line for either Eclipse or WindRiver or on running makefiles on Windows? I tried looking at "How to run a makefile in Windows?" but following the first answer didn't work (it gave a syntax error for the makefile).
I'm currently using a Windows 8 laptop. As best as I can tell, the current varient of WindRiver I'm using is based on Eclipse version 3.3.1.
You will need a make utility, I believe your WindRiver / Eclipse setup would come with "gnumake" (probably called either make or gmake). You'd nee dto set up the command line path to lead to the compiler and the make executable. Unfortunately, this is not a great answer, as I can't give you exact links to the make and compiler locations (it would of course also depend on where you installed things). I just thought I'd lead you somewhat on the right path, since the question has been up for a little while and no one jumped at it.
Thanks to Mat Petersson's answer, I was able to identify everything I needed and create a batch file that could compile the file for me:
#echo off
setlocal
set PATH=%PATH%;C:\WindRiver\gnu\3.4.4-vxworks-6.3\x86-win32\bin;C:\WindRiver\utilities-1.0\x86-win32\bin;C:\WindRiver\setup\x86-win32\bin
set WIND_BASE=C:\WindRiver\vxworks-6.3
cd My_Project\PPC603gnu
make --no-print-directory BUILD_SPEC=PPC603gnu DEBUG_MODE=1 TRACE=1

How to run C++ program that use PDCurses on other computers?

I've recently started using PDCurses in a C++ game I'm working on. When I compile the program on my own machine (windows) and run the .exe, everything works as it should.
When I take that .exe onto a different computer that doesn't have PDCurses and I try to run it, I get an error about a missing pdcurses.dll file.
After doing a bit of research online, I found out that including the .dll file along with the .exe should make it run but it didn't work for me.
This is how I compiled the program using MinGW: g++ game.cpp -o game -lpdcurses
So my question is, how do I make this program run on computers that don't have PDCurses setup, and also, is there a way to do this by combining the .exe with whatever additional file(s) the system needs to run the program? I've also read that you can do some sort of static linking but so far I've been unable to find a way to do this.
Thanks in advance for the help.
NOTE: In case it matters, I setup PDCurses following this tutorial: http://comptb.cects.com/1848-adding-pdcurses-to-mingw
Not sure if that was the best way to do it but I'm able to compile and run C++ code that uses pdcurses on my computer fine.
Sorry for not posting the exact messages. Here they are:
The first one I got when I didn't include the pdcurses.dll file along with the executable said :
The program can't start because pdcurses.dll is missing from your computer. Try reinstalling the program to fix this problem.
The second one I got after I included the pdcurses.dll:
*The program can't start because libcc_s_dw2-1.dll is missing from your computer. Try reinstalling the program to fix this problem.*
You need to include all the dynamic libraries you linked with. Be careful of licensing, although IIRC there's not much that will bite you with MinGW.
There should be a 'ldd' command if you have the MinGW shell. Try running it on game.exe and it will tell you what libraries you need to run your program. You need to include them all with the exe.
If you want to try and remove the dependency nightmare you can use the static linking (-static) option to your gcc link command. You may not be able to actually do that if you don't have the static versions of your libraries installed. This has other implications - your exe will be bigger and the OS's shared shared page code will not work because it can't tell what parts (DLL code) you are sharing with other apps. In effect, your application will use more memory as a result, although it may be insignificant.
Another option is to get the sources to PDCurses and compile it as a static library. That way you don't have to get involved in the DLL Hell.
Compile it as a C library instead of a C++ library and you should be good to go.

Setting up midiIO library on Windows

I've downloaded the midiIO library and in the readme it says:
edit the file Makefile.library and set the OSTYPE and OSSUBTYPE to match your hardware/os setup.
type "make library" to compile the library. It will be created as lib/libmidiio.a in unix.
edit the file Makefile.examples and set the OSTYPE and OSSUBTYPE to match your hardware/os setup.
Also, if you are using ALSA, then uncomment out the POSTFLAG to use the alsa library (-lasound).
type "make examples" to compile the example programs in the examples directory. The example programs will be place in the bin directory.
1 + 3 are fine but 2 + 4 are over my head. I've worked in a unix environment before and have used gcc with flags but I need to get this done in Windows. I typically use Visual Studio but don't know how to achieve this with that.. I've downloaded Dev-C++ if that's any use but I don't know what to do with the makefiles?
Ignore the makefiles and set up a fresh project in Visual C++. Make your target a static library (which will be a .lib file in Win32, not a .a file as in unix as you probably know). It is unlikely that the project will build out of the box, so you might have to deal with some compilation errors relating to unix-specific symbols. I took a quick look at the source code, and it looks fairly well-written, so I don't think you should have many problems building it directly in Windows.
Alternately, you could build the source using the real make tool in cygwin, but this means that you would need to distribute the cygwin library with your final product. This may or may not be more trouble than it's worth, especially if you are already using VC++ for the rest of your project's code.

Import existing C++ project into Xcode IDE

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.