Compiling magick++ stuff in Code::Blocks - c++

I'm doing some experimenting with magick++ and when I compile my snippets I just use g++ and type g++ test.cpp `Magick++-config --cppflags --cxxflags --ldflags --libs` -o prog but I have recently fallen in love Code:Blocks and I'm wondering how I can tell it to compile like above? I haven't been able to figure it out on my own.

Open from menu →Project →Build Options
Navigate to →Compiler settings →OtherOptions and enter:
$\(Magick++-config --cppflags --cxxflags\)
Navigate to →Linker settings and enter to →Other linker options:
$\(Magick++-config --ldflags --libs\)
Escaping \( and \) are necessary.
Remember to select the project on left, not a build target.

Related

Trouble compiling code from LLVM Kaleidoscope tutorial

When I used g++ -std=c++17 toy.cpp -o toy to compile the toy.cpp file without the header #include "llvm/ADT/STLExtras.h" in the toy.cpp file, everything was fine and I produced a "working" binary file.
However, when I added the #include "llvm/ADT/STLExtras.h" line to the toy.cpp file and compile it with the command g++ -std=c++17 toy.cpp -o toy, the terminal crushed me with the following output:
-bash: llvm-config: command not found
toy.cpp:1:10: fatal error: 'llvm/ADT/STLExtras.h' file not found
#include "llvm/ADT/STLExtras.h"
The same thing still happens even if I used
"clang++ -g -O3 toy.cpp llvm-config --cxxflags --ldflags --system-libs --libs core -o toy"
instead of "clang++ -g -O3 toy.cpp llvm-config --cxxflag" in the tutorial. My guess is that there's something wrong with the llvm-config thing. It's been bothering me for a while, please teach me how to solve it.
Link to the toy.cpp code
The answer to this is "llvm-config" is not working as expected.
Just check with which llvm-config to figure out whether you got this program. (mine is /usr/local/opt/llvm#8/bin/llvm-config). Or you can install with brew install llvm.
By the way, I came up with the same issue lately on kaleidoscope tutorial (ch2), but I want to know why the #include "llvm/ADT/STLExtras.h fails after several attempts on $(llvm-config --cxxflags --ldflags), etc or we aren't able to compile following chapter's code simply by removing the header declaration when llvm include files are necessary.

I cannot seem to get SDL to work with sublime text

I am making a simple game and wanted to use SDL for the graphics. I run linux Ubuntu, and use sublime text editor, g++ compiler, and I am coding in c++. I downloaded SDL and followed these steps.
After I followed those steps, all of the SDL error stopped appearing. However, the flag variables aren't working.
This is the code:
#include <SDL2/SDL.h>
Risk() {
SDL_Init(SDL_INIT_HAPTIC);
window = SDL_CreateWindow("Board",SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 500,500, SDL_WINDOW_RESIZABLE);
SDL_GetError();
}
The error appearing in my compiler is:
tom#TBT-XPS-13-9360:~/Documents/Subjects/CS/Fun/Risk$ g++ -std=c++14
Game.cpp -W/tmp/ccLwSxiL.o: In function `Risk::Risk()':
Game.cpp:(.text._ZN4RiskC2Ev[_ZN4RiskC5Ev]+0x1f): undefined reference
to `SDL_Init'
Game.cpp:(.text._ZN4RiskC2Ev[_ZN4RiskC5Ev]+0x44): undefined reference
to `SDL_CreateWindow'
Game.cpp:(.text._ZN4RiskC2Ev[_ZN4RiskC5Ev]+0x54): undefined reference
to `SDL_GetError'
collect2: error: ld returned 1 exit status
I think the error is the SDL libraries are in the wrong place, or Sublime doesn't know where they are.
The problem is that Sublime is not adding the required instruction to indicate that the executable should be linked to the SDL2 library.
You can indicate it with the parameter -lSDL2 on the command line, or use the sdl2-config program with sdl2-config --libs, something like this:
$ g++ -o executable-name source.cpp -lSDL2
or
$ g++ -o executable-name source.cpp $(sdl2-config --libs)
sdl2-config is just an utility that outputs appropriate configuration options for compiling and linking. You can see it by running it alone:
$ sdl2-config --libs
it should output something like:
-L/usr/lib -lSDL2
You can see the same -lSDL2 mentioned before, and also a -L/usr/lib instruction that indicates the linker to include libraries in the /usr/lib/ directory in its search path.
In general, you should use the sdl2-config for getting the required configuration options to pass to the compiler instead of indicating them by yourself, unless you know what you're doing, of course.
Instead of going to the command line to compile, you can use the Make build system in Sublime Text. Add a file named Makefile to your project directory with the following content:
# OBJS place here every file to compile as part of the project
OBJS = Game.cpp
# CC compiler to use
CC = g++
# COMPILER_FLAGS compilation options
COMPILER_FLAGS = -std=c++14 -Wall `sdl2-config --cflags`
# LINKER_FLAGS libraries to link
LINKER_FLAGS = `sdl2-config --libs`
# OBJ_NAME executable
OBJ_NAME = mygame
all : $(OBJS)
$(CC) $(OBJS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $(OBJ_NAME)
Then go to menu Tools -> Build System and select Make. Now try building your project, if successful, a mygame executable should have been created.

Running a SFML C++ program with minGW on Windows 10

So I'm trying to run an example SFML program on my Windows laptop. If relevant, the source code is on this page.
So first I make the .o file using this command -
g++ -c a.cpp -ISFML/SFML/include
Where a.cpp is the main file, and my SFML package is located in SFML/SFML.
Then I compile using this command -
g++ a.o -o a -LSFML/SFML/lib -lsfml-graphics -lsfml-window -lsfml-system
When I first ran the program I got the errors about not being able to find certain dlls, sfml-graphics-2 etc. So I found them and put them next to the exe. But now when I run, I get this weird error:
The procedure entry point
_ZNSt7__cxx1112basic_stringSt11char_traitsIcESalcEE7reserveEj could not be located in the dynamic link library.
What is going on here?
As the SFML download page states, You could be using the wrong version of the compiler, other library versions of SFML that you have not removed from your working directory that could mismatch between code and linker. Worst case, if your compiler is not listed there, you have to compile SFML yourself:
Get CMake. Get the source code for 2.4.2 by going to the bottom of the SFML download page. Follow this guide on SFML's GitHub repo. Alternatively, you could use the guide on SFML's page but it is for an older version. It might answer some questions that the first guide misses.
Ones CMake have generated the makefiles, you're on your way to build SFML.
Good luck!
I've had this problem for so long so I just wanted to help someone out who had the same problem. I have a windows 10 FYI and MinGW-w64 8.1.0 (if it doesnt work try a 32 bit mingw instead)
for a debug mode (debug is when your still working on the game and would like command prompt to open whenever you run it)
(make sure your in the right directory first by doing "cd")
g++ -c (file_name).cpp -o (file_name).o -I(path_to)SFML-64-bit/include -g -m64 -Wall &&
g++ (file_name).o -o (game_name).exe -L(path_to)SFML-64-bit/lib -lsfml-graphics -lsfml-window -lsfml-system
The code above when placed in command will compile everything for you if its all in the same directory so make sure you keep an eye out for that
and now for release mode (if you dont want command prompt to show up)
g++ -c (file_name).cpp -o (file_name).o -I(path_to)SFML-64-bit/include -O3 -m64 &&
g++ (file_name).o -o (game_name).exe -L(path_to)SFML-64-bit/lib -lsfml-graphics lsfml-window -lsfml-system -mwindows
Noticed all I added was the -mwindows and the -O3 aswell as removing -g and -Wall which are not necessary since we wont be using command prompt
Make sure to go to SFML/bin and take all the .dlls and put it into the same directory has your .exe sorry xd
Hope this helped.

Setting Up CPLEX in Eclipse C++ on Linux

I have installed CPLEX 12.6.3 (CPLEX_Studio_Community1263) and I want to integrate CPLEX in my Eclipse C++ project (on Linux). But I don't know which steps I have to follow to include CPLEX in my project.
Even by following exactly the steps shown at this link, it still not working for me (I can't import cpelx.jar in my project). The path of my cplex.jar is
/opt/ibm/ILOG/CPLEX_Studio_Community1263/cplex/lib/cpelx.jar
When I right-click on my project and go to
Properties --> Settings --> GCC C++ Linker --> Libraries
to add the cplex.jar in my project, it is impossible to add the .jar because I can't select it (it is deselected and impossible to select it).
Can some one explain me how I can include CPLEX in my project?
The link you reference is for setting up a Java program. This will not help you.
Instead, you should try running one of the C++ examples shipped with CPLEX. Try the following (assuming your path is correct from above):
$ cd /opt/ibm/ILOG/CPLEX_Studio_Community1263/cplex/examples/x86-64_linux/static_pic
$ make ilolpex1 2>&1 | tee output.txt
This will save the output in output.txt so that you can look at it later. It should give you an idea of what the required command line arguments are.
For example, on my system (x86-64_linux), I see this in the output:
$ make ilolpex1
g++ -O0 -c -m64 -O -fPIC -fno-strict-aliasing -fexceptions -DNDEBUG -DIL_STD -I../../../include -I../../../../concert/include ../../../examples/src/cpp/ilolpex1.cpp -o ilolpex1.o
g++ -O0 -m64 -O -fPIC -fno-strict-aliasing -fexceptions -DNDEBUG -DIL_STD -I../../../include -I../../../../concert/include -L../../../lib/x86-64_linux/static_pic -L../../../../concert/lib/x86-64_linux/static_pic -o ilolpex1 ilolpex1.o -lconcert -lilocplex -lcplex -lm -lpthread
This tells you everything you need to know to compile and link your program. You'll just need to figure out where to enter this information in Eclipse.

Setting up Netbeans to compile wxWidgets projects under Windows

I'm trying to set up my Netbeans IDE so that it is capable of compiling wxWidgets projects.
There is very similar question:
Setup wxWidget in Netbeans 6.1 C++ On MS Windows?
but the answer is not working for me. And the mentioned versions are a bit outdated.
I use the mingw package for compilation.
There is no problem compiling a small hello World App from the console using this command in mysys:
$ g++ hello.cpp `wx-config --libs` `wx-config --cxxflags` -o hello.exe
So here's what I tried in Netbeans:
Project properties:
C++ Compiler -> Additional Options: wx-config cxxflags (surrounded by backticks)
C++ Compiler -> Include directories: installation_Path/include
Linker -> Additional Options: wx-config --libs (surrounded by backticks)
The command lines Netbeans creates when I try to compile seem to be correct to me
g++.exe `wx-config --cxxflags` -c -g -I/D/lib/wxWidgets/include -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o build/Debug/MinGW-Windows/main.o main.cpp
This compiles without errors
g++.exe `wx-config --cxxflags` `wx-config --libs` -o dist/Debug/MinGW-Windows/wxwidgetstest build/Debug/MinGW-Windows/main.o -L/D/lib/wxWidgets/lib/gcc_lib
But during the linking process I get loads of errors...
Questions:
Does anybody have a working configuration for compiling wxWidgets Projects from within Netbeans and can help me out
Or does anybody see an error in the command lines could be the reason for the linking problems ?
Thank you very much!
I finally found the solution, and wrote a guide for anyone who might encounter the same problem in the future.
wxWidgets wiki: Compiling using Netbeans