directxtutorial.com tutorial wont compile in g++ - c++

I am hoping that there is just come compiler settings I can adjust somewhere. I try to complie the source code here: http://www.directxtutorial.com/Lesson.aspx?lessonid=9-4-1
It will compile in visual studio 2010 but when I try to compile in g++ through netbeans it gives me these errors
"/usr/bin/make" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/cygdrive/c/Users/Stephen/Documents/Projects/C++/test'
"/usr/bin/make" -f nbproject/Makefile-Release.mk dist/Release/Cygwin-Windows/test.exe
make[2]: Entering directory `/cygdrive/c/Users/Stephen/Documents/Projects/C++/test'
mkdir -p build/Release/Cygwin-Windows
rm -f build/Release/Cygwin-Windows/main.o.d
g++.exe -c -g -MMD -MP -MF build/Release/Cygwin-Windows/main.o.d -o build/Release/Cygwin-Windows/main.o main.cpp
main.cpp: In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)':
main.cpp:39: error: cannot convert `const wchar_t[12]' to `const CHAR*' in assignment
main.cpp:52: warning: converting to non-pointer type `DWORD' from NULL
main.cpp:52: error: cannot convert `const wchar_t*' to `const CHAR*' for argument `2' to `HWND__* CreateWindowExA(DWORD, const CHAR*, const CHAR*, DWORD, int, int, int, int, HWND__*, HMENU__*, HINSTANCE__*, void*)'
nbproject/Makefile-Release.mk:66: recipe for target `build/Release/Cygwin-Windows/main.o' failed
make[2]: *** [build/Release/Cygwin-Windows/main.o] Error 1
make[2]: Leaving directory `/cygdrive/c/Users/Stephen/Documents/Projects/C++/test'
make[1]: *** [.build-conf] Error 2
nbproject/Makefile-Release.mk:59: recipe for target `.build-conf' failed
make: *** [.build-impl] Error 2
make[1]: Leaving directory `/cygdrive/c/Users/Stephen/Documents/Projects/C++/test'
nbproject/Makefile-impl.mk:39: recipe for target `.build-impl' failed
BUILD FAILED (exit value 2, total time: 1s)
I can easily get rid of the main.cpp: 39 and 52 errors, the rest wont go through

Use MinGW for WIN32 sources, not Cygwin.

Related

Regex code stopped working for no reason

Here's the code that I'm trying to build and compile. I'm not sure what I did, but this code worked before (a couple of weeks ago).
#include <regex>
using namespace std;
int main(int argc, char** argv) {
regex txt_regex("[a-z]+\\.txt");
return 0;
}
Here's the error log from netbeans:
cd '/home/dev/Desktop/test'
/usr/bin/make -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/home/dev/Desktop/test'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/test
make[2]: Entering directory '/home/dev/Desktop/test'
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/main.o.d"
g++ -c -g -std=c++11 -MMD -MP -MF "build/Debug/GNU-Linux/main.o.d" -o build/Debug/GNU-Linux/main.o main.cpp
In file included from /usr/include/c++/5/regex:60:0,
from main.cpp:1:
/usr/include/c++/5/bits/regex_compiler.h: In member function ‘bool std::__detail::_AnyMatcher<_TraitsT, false, __icase, __collate>::operator()(std::__detail::_AnyMatcher<_TraitsT, false, __icase, __collate>::_CharT) const [with _TraitsT = std::__cxx11::regex_traits<char>; bool __icase = true; bool __collate = false; std::__detail::_AnyMatcher<_TraitsT, false, __icase, __collate>::_CharT = char]’:
/usr/include/c++/5/bits/regex_compiler.h:292:7: internal compiler error: Segmentation fault
operator()(_CharT __ch) const
^
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-5/README.Bugs> for instructions.
nbproject/Makefile-Debug.mk:66: recipe for target 'build/Debug/GNU-Linux/main.o' failed
make[2]: *** [build/Debug/GNU-Linux/main.o] Error 1
make[2]: Leaving directory '/home/dev/Desktop/test'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/home/dev/Desktop/test'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
What's going on?
The code works again after I updated my system:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade

Undefined reference to sf::

I wanted to make gui apps in c++ and found SFML to be a good choice. Fortunately i am on linux so SFML(2.4) was already installed on my system.
So i started searching for some tutorials and found one that makes a simple window. But when i run the code i get an error saying undefined reference to sf::(function i am using). Here's the code
#include <SFML/Graphics.hpp>
int main(void)
{
sf::RenderWindow window(sf::VideoMode(640,480),"SFML working");
return 0;
}
And here's the error log.
cd '/home/jasper/NetBeansProjects/SFML'
/usr/bin/make -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/home/jasper/NetBeansProjects/SFML'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/sfml
make[2]: Entering directory '/home/jasper/NetBeansProjects/SFML'
mkdir -p dist/Debug/GNU-Linux
g++ -o dist/Debug/GNU-Linux/sfml build/Debug/GNU-Linux/main.o
build/Debug/GNU-Linux/main.o: In function `main':
/home/jasper/NetBeansProjects/SFML/main.cpp:6: undefined reference to `sf::String::String(char const*, std::locale const&)'
/home/jasper/NetBeansProjects/SFML/main.cpp:6: undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
/home/jasper/NetBeansProjects/SFML/main.cpp:6: undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
/home/jasper/NetBeansProjects/SFML/main.cpp:6: undefined reference to `sf::RenderWindow::~RenderWindow()'
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:62: recipe for target 'dist/Debug/GNU-Linux/sfml' failed
make[2]: *** [dist/Debug/GNU-Linux/sfml] Error 1
make[2]: Leaving directory '/home/jasper/NetBeansProjects/SFML'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/home/jasper/NetBeansProjects/SFML'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 172ms)
I've tried searching for solution on google but couldn't find any effective one. So i thought some expert opinion would be good. Help please. Thanks
You forgot to link with SFML libraries. Those are at least:
sfml-graphics
sfml-window
sfml-system
As the documentation explains, on Linux it can be done like this:
g++ myapp.o -o myapp -lsfml-graphics -lsfml-window -lsfml-system
Or if using an IDE, specify them as Additional Dependencies in Linker settings.

NetBeans building failure | make Error 1

I get the following errors while building my project (game with C++/SFML):
cd '/home/osboxes/NetBeansProjects/Prueba'
/usr/bin/make -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/home/osboxes/NetBeansProjects/Prueba'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/prueba
make[2]: Entering directory '/home/osboxes/NetBeansProjects/Prueba'
mkdir -p dist/Debug/GNU-Linux
g++ -o dist/Debug/GNU-Linux/prueba build/Debug/GNU-Linux/AABBCollidable.o build/Debug/GNU-Linux/AABBCollisionDetector.o build/Debug/GNU-Linux/AnimatedSprite.o build/Debug/GNU-Linux/Animation.o build/Debug/GNU-Linux/ConvexCollidable.o build/Debug/GNU-Linux/ConvexCollisionDetector.o build/Debug/GNU-Linux/ConvexShape.o build/Debug/GNU-Linux/Director.o build/Debug/GNU-Linux/Entry.o build/Debug/GNU-Linux/Event.o build/Debug/GNU-Linux/EventManager.o build/Debug/GNU-Linux/FileLogger.o build/Debug/GNU-Linux/GuiElement.o build/Debug/GNU-Linux/GuiSystem.o build/Debug/GNU-Linux/Label.o build/Debug/GNU-Linux/LabelButton.o build/Debug/GNU-Linux/ResourceManager.o build/Debug/GNU-Linux/State.o -L/usr/lib/x86_64-linux-gnu -lsfml-window -lsfml-system -lsfml-graphics -lsfml-audio
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start':
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:79: recipe for target 'dist/Debug/GNU-Linux/prueba' failed
make[2]: *** [dist/Debug/GNU-Linux/prueba] Error 1
make[2]: Leaving directory '/home/osboxes/NetBeansProjects/Prueba'
nbproject/Makefile-Debug.mk:76: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/home/osboxes/NetBeansProjects/Prueba'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 2s)
I have installed NetBeans IDE 8.1 with SFML libraries. I tried to fix it by clearing cache from NetBeans and then restart IDE but still does the same errors.
My project was compiled with Standard C++ compiler (C++11 version).
Hope you could help me. Thanks by the way...

(C++) Why is it that defining a constructor causes my program to not compile?

I'm (somewhat) new to C++ and I've been trying to get a program to work. It all compiles fine until I start to define a class constructor within the source file, even though I have declared it in the header file. I'm not sure if it's because I haven't defined all of my methods, because this is my second attempt at defining them (I'm literally rewriting them slowly to see if it helps).
The code in question is below (this is what is on the cpp file):
#include <cstdlib>
#include <iostream>
#include <string.h>
#include "StockItem.h"
Diode::Diode(char* componentT, char* code, int quantity, int price){
strcpy(componentType,componentT);
strcpy(stockCode,code);
stockQuantity = quantity;
unitPrice = price;
}
The output I receive is below:
cd 'G:\EDUCATION\University\Year 2\Year Courses\PROGRAMMING 2\Assignments\Assignment 2\COURSEWORK_100088688\StockProgram_C++'
C:\cygwin\bin\make.exe -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/g/EDUCATION/University/Year 2/Year Courses/PROGRAMMING 2/Assignments/Assignment 2/COURSEWORK_100088688/StockProgram_C++'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin-Windows/stockprogram_c__.exe
make[2]: Entering directory '/cygdrive/g/EDUCATION/University/Year 2/Year Courses/PROGRAMMING 2/Assignments/Assignment 2/COURSEWORK_100088688/StockProgram_C++'
mkdir -p build/Debug/Cygwin-Windows
rm -f "build/Debug/Cygwin-Windows/StockItem.o.d"
g++ -c -g -std=c++11 -MMD -MP -MF "build/Debug/Cygwin-Windows/StockItem.o.d" -o build/Debug/Cygwin-Windows/StockItem.o StockItem.cpp
StockItem.cpp: In member function 'void StockItem::setComponentType(char*)':
StockItem.cpp:27:16: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
char* S1 = "resistor";
^
StockItem.cpp:28:16: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
char* S2 = "capacitor";
^
StockItem.cpp:29:16: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
char* S3 = "transistor";
^
StockItem.cpp:30:16: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
char* S4 = "diode";
^
StockItem.cpp:31:16: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
char* S5 = "ic";
^
mkdir -p build/Debug/Cygwin-Windows
rm -f "build/Debug/Cygwin-Windows/StockProgram.o.d"
g++ -c -g -std=c++11 -MMD -MP -MF "build/Debug/Cygwin-Windows/StockProgram.o.d" -o build/Debug/Cygwin-Windows/StockProgram.o StockProgram.cpp
mkdir -p dist/Debug/Cygwin-Windows
g++ -o dist/Debug/Cygwin-Windows/stockprogram_c__ build/Debug/Cygwin-Windows/StockItem.o build/Debug/Cygwin-Windows/StockProgram.o
build/Debug/Cygwin-Windows/StockItem.o: In function `ZN9StockItemC2Ev':
/cygdrive/g/EDUCATION/University/Year 2/Year Courses/PROGRAMMING 2/Assignments/Assignment 2/COURSEWORK_100088688/StockProgram_C++/StockItem.h:8: undefined reference to `vtable for StockItem'
build/Debug/Cygwin-Windows/StockItem.o:StockItem.cpp:(.rdata$_ZTV5Diode[__ZTV5Diode]+0x8): undefined reference to `StockItem::getComponentInfo()'
build/Debug/Cygwin-Windows/StockItem.o:StockItem.cpp:(.rdata$_ZTV5Diode[__ZTV5Diode]+0xc): undefined reference to `StockItem::setComponentInfo(char*)'
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:63: recipe for target 'dist/Debug/Cygwin-Windows/stockprogram_c__.exe' failed
make[2]: *** [dist/Debug/Cygwin-Windows/stockprogram_c__.exe] Error 1
make[2]: Leaving directory '/cygdrive/g/EDUCATION/University/Year 2/Year Courses/PROGRAMMING 2/Assignments/Assignment 2/COURSEWORK_100088688/StockProgram_C++'
nbproject/Makefile-Debug.mk:60: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/cygdrive/g/EDUCATION/University/Year 2/Year Courses/PROGRAMMING 2/Assignments/Assignment 2/COURSEWORK_100088688/StockProgram_C++'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 5s)
And just in case people need it, this is the class in question:
class Diode : public StockItem {
public:
Diode(char* componentT, char* code, int quantity, int price);
Diode(const Diode &D);
Diode& operator=(const Diode& D);
~Diode();
};
My question is why is this effecting the compilation? Any feedback (regardless of relevance) is greatly appreciated, thank you.
Error comes from undefined reference when linking.
You declare the functions, use them, but never implement the functions.
When linker link the object files and lib files, it would check the export symbols and import symbols then match them together.
Obvious, in your case, other class use your functions, treated as import symbols, but in class's object file, doesn't contain the function in export symbols table.

configuring NetBeans to work with DirectX

I have NetBeans 7.2.1 with Cygwin compiler installed. I want to setup Direct X in NetBeans, so I right clicked on the project -> properties -> C++ Compiler -> Include Directories, and added the include in DirectX SDK, went to properties again -> Linker -> Additional Library Directories and added the Lib(x86) in DirectX SDK. But when I compile this shows up:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/cygdrive/c/Users/Jacob/Documents/NetBeansProjects/DX_trial'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin-Windows/dx_trial.exe
make[2]: Entering directory `/cygdrive/c/Users/Jacob/Documents/NetBeansProjects /DX_trial'
mkdir -p build/Debug/Cygwin-Windows
rm -f build/Debug/Cygwin-Windows/main.o.d
g++.exe -c -g -I/cygdrive/D/Direct\ X\ SDK/Include -MMD -MP -MF build/Debug/Cygwin- Windows/main.o.d -o build/Debug/Cygwin-Windows/main.o main.cpp
main.cpp: In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)':
main.cpp:60: warning: passing NULL used for non-pointer converting 1 of `HWND__* CreateWindowExA(DWORD, const CHAR*, const CHAR*, DWORD, int, int, int, int, HWND__*, HMENU__*, HINSTANCE__*, void*)'
main.cpp:191:2: warning: no newline at end of file
mkdir -p dist/Debug/Cygwin-Windows
g++.exe -o dist/Debug/Cygwin-Windows/dx_trial build/Debug/Cygwin-Windows/main.o -L/cygdrive/D/Direct\ X\ SDK/Lib/x86
build/Debug/Cygwin-Windows/main.o: In function `_Z7initD3DP6HWND__':
/cygdrive/c/Users/Jacob/Documents/NetBeansProjects/DX_trial/main.cpp:111: undefined reference to `_Direct3DCreate9#4'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/Cygwin-Windows/dx_trial.exe] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
nbproject/Makefile-Debug.mk:62: recipe for target `dist/Debug/Cygwin-Windows /dx_trial.exe' failed
make[2]: Leaving directory `/cygdrive/c/Users/Jacob/Documents/NetBeansProjects /DX_trial'
nbproject/Makefile-Debug.mk:59: recipe for target `.build-conf' failed
make[1]: Leaving directory `/cygdrive/c/Users/Jacob/Documents/NetBeansProjects /DX_trial'
nbproject/Makefile-impl.mk:39: recipe for target `.build-impl' failed
BUILD FAILED (exit value 2, total time: 2s)
Is there a problem in the configuration? ,because the code I copied and pasted from a tutorial and it worked on another compiler. Any help at all would be appreciated.