Problems in setting up GLFW in CodeBlocks - opengl

I downloaded GLFW 3.1.1 and followed a tutorial telling me to:
Drop glfw3.h into MinGW's include folder
Drop the contents of lib-mingw in the downloaded file into MinGW's lib folder
Run the test program that comes with GLFW
After doing this I kept running into an error that stopped me from even starting a new GLFW project as the wizard kept looking for glfw.h and glfw.dll when they're now glfw3.h and glf3.dll I edited the wizard and was finally able to get the new project open.
After that, I clicked build and run and the compiler asked if I was sure. When I clicked yes it continually asked me if I wanted to build and run. The debugger just gives me this and I'm not sure what I set up wrong.
-------------- Build: Debug in 112311 (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Wall -g -I"C:\Program Files\MinGW\include" -c "C:\Users\User\Desktop\Folders\C++ Files\112311\main.cpp" -o obj\Debug\main.o
Execution of 'mingw32-g++.exe -Wall -g -I"C:\Program Files\MinGW\include" -c "C:\Users\User\Desktop\Folders\C++ Files\112311\main.cpp" -o obj\Debug\main.o' in 'C:\Users\User\Desktop\Folders\C++ Files\112311' failed.
-------------- Run: Debug in 112311 (compiler: GNU GCC Compiler)---------------
Checking for existence: C:\Users\User\Desktop\Folders\C++ Files\112311\bin\Debug\112311.exe
i

You should avoid using the wizard for GLFW projects because it's for an outdated version of GLFW.
You should create a console application then go to Project->Build Options. Go to the Linker settings tab then add glfw3, opengl32 and gdi32, then click OK.
You can now test if it worked by copying the sample code on the GLFW website's documentation page and pasting it in main.cpp, replacing everything and running the program.

Related

C++ CodeBlocks and wxWidgets file not found?

I'm pretty new to C::B and just installed it along with building wxWidgets. I'm pretty sure my wxWidgets build with MinGW is good, i was able to successfully create a wxWidgets project in C::B using the "minimal.cpp" sample in wxWidgets. However now instead of creating an empty project, I'm using leaving "Empty project" unchecked in wizard to create the program. With wxWidgets this creates 2 source files and 2 header files (for app and main). When I try to build+play the project though without making any changes i get this error:
-------------- Build: Debug in MULLSIMPLE (compiler: GNU GCC Compiler)---------------
g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -Winvalid-pch -include wx_pch.h -DWX_PRECOMP -Wall -g -D__WXDEBUG__ -I"C:\Program Files\wxWidgets-3.0.5\include" -I"C:\Program Files\wxWidgets-3.0.5\lib\gcc_dll\mswud" -c "C:\Users\gmloo\OneDrive\Desktop\C++ Projects\MULLSIMPLE\wx_pch.h" -o wx_pch.h.gch\Debug_wx_pch_h_gch
g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -Winvalid-pch -include wx_pch.h -DWX_PRECOMP -Wall -g -D__WXDEBUG__ -I"C:\Program Files\wxWidgets-3.0.5\include" -I"C:\Program Files\wxWidgets-3.0.5\lib\gcc_dll\mswud" -c "C:\Users\gmloo\OneDrive\Desktop\C++ Projects\MULLSIMPLE\MULLSIMPLEApp.cpp" -o obj\Debug\MULLSIMPLEApp.o
g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -Winvalid-pch -include wx_pch.h -DWX_PRECOMP -Wall -g -D__WXDEBUG__ -I"C:\Program Files\wxWidgets-3.0.5\include" -I"C:\Program Files\wxWidgets-3.0.5\lib\gcc_dll\mswud" -c "C:\Users\gmloo\OneDrive\Desktop\C++ Projects\MULLSIMPLE\MULLSIMPLEMain.cpp" -o obj\Debug\MULLSIMPLEMain.o
windres.exe -I"C:\Program Files\wxWidgets-3.0.5\include" -I"C:\Program Files\wxWidgets-3.0.5\lib\gcc_dll\mswud" -J rc -O coff -i C:\Users\gmloo\OneDrive\Desktop\C__PRO~1\MULLSI~1\resource.rc -o obj\Debug\resource.res
g++.exe -L"C:\Program Files\wxWidgets-3.0.5\lib\gcc_dll" -o bin\Debug\MULLSIMPLE.exe obj\Debug\MULLSIMPLEApp.o obj\Debug\MULLSIMPLEMain.o obj\Debug\resource.res -mthreads -lwxmsw30ud_core -lwxbase30ud -lwxpngd -lwxzlibd -mwindows
gcc: error: Files\wxWidgets-3.0.5\include: No such file or directory
gcc: error: Files\wxWidgets-3.0.5\lib\gcc_dll\mswud: No such file or directory
windres.exe: preprocessing failed.
Process terminated with status 1 (0 minute(s), 14 second(s))
Process terminated with status 0 (0 minute(s), 16 second(s))
3 error(s), 0 warning(s) (0 minute(s), 16 second(s))
Saying that it can't find files? the wxWidgets-3.0.5 is actually in c:\Program Files/wxWidgets-3.0.5, so maybe its looking in the wrong place? Or maybe I missed a step setting it up?
This is absolutely everything I did to install C::B, install wxWidgets, and create my project
1. Installing CodeBlocks
a. Clicked codeblocks-20.03mingw-setup.exe from website, then download started automaticallty from fosshub
b. Ran executable to install and for type of install did "All plugins, all tools, just everything"
-all checkboxes were checked, including
1. Default Install
2. Contrib Plugins
3. C::B CBP2Make
4. C::B Share Config
5. C::B Launcher
6. MinGW Compiler Suite
2. Downloading wxWidgets
a. Clicked "Windows ZIP" from downloads page on website under "Latest Stable Release: 3.0.5"
b. Extracted download to c:\Program Files\wxWidgets-3.0.5
-first file asked for administrator permission, i said "dont ask again" and clicked "continue"
3. Added MinGW to path
a. went into c:\Program Files\CodeBlocks\MinGW\bin and copied that path to PATH environment variables
4. Building wxWidgets
a. opened a terminal with admin privileges and went to c:\Program Files\wxWidgets-3.0.5\build\msw.
b. entered commands as suggested at https://wiki.wxwidgets.org/Compiling_wxWidgets_with_MinGW, except changed
BUILD=release to BUILD=debug:
1. mingw32-make -f makefile.gcc SHARED=1 UNICODE=1 BUILD=debug clean
2. mingw32-make -f makefile.gcc SHARED=1 UNICODE=1 BUILD=debug
c. wxWidgets successfully built (3:38 pm to 4:22pm!)
5. Opened CodeBlocks
a. got message that "After auto-detection, at least one compiler's master path is still empty and therefore invalid.
Inspect the list below and change the compiler's master path later in the compiler options. Select you favourite
default compiler here:"
-There's one compiler listed as detected: GNU GCC Compiler
-With this compiler highlighted, i clicked "Set as default" and then ok.
b. got message CodeBlocks is not default app for C/C++ source files.
-Selected "Yes, associate with C/C++ files"
7. Testing Compiler
-I wasn't sure what to do about "setting compiler master path..." msg earlier, so I just created a new project with type
"Console application", compiled the basic "Hello world" application, ran it, ran fine, so I assume compiler is working?
6. Create new wxWidgets program:
a. Create new project: wxWidgets project
b. Wizard Steps:
PAGE 1:
-Set version: wxWidgets 3.0.x
PAGE 2:
-Named project "MULLSIMPLE" and created directory
PAGE 3:
-Skipped Author info.
PAGE 4:
-Preferred GUI Builder: None
-Application Type: Frame Based
PAGE 5:
-wxWidgets location: C:\Program Files\wxWidgets-3.0.5
-When I hit next, it opens the global variable editor. I don't know how to use this,
so i just hit ok without making any changes. IT asked if i want to save an invalid global var,
i said yes. Now the widgets location in the wizard is a path instead of a global variable,
I assume this is ok for now
PAGE 6:
-By default "Debug" configuration checked, "Release" configuration is unchecked
-make no changes
PAGE 7:
-Under wxWidgets library settings:
-CHECK Use wxWidgets DLL
-UNCHECK wxWidgets built as monolithic
-CHECK enable unicode
-Under Miscellaneous settings:
-UNCHECK create empty project
-CHECK create and use PCH
-Leave configuration input field blank
-UNCHECK Configure Advanced Options
-On next get dialog re PCH default settings, click YES to accept
PAGE 8:
-Didn't select any additional libs to add to project,
just hit finish
8. Try Build and run
-Get the build log error at start of post re: missing files
Thanks
#user4581301 thanks for your response it looks like that was the problem. I copied the wxWidgets-3.0.5 to the desktop. Then i opened up the old one in prog files, cleaned the build, then deleted that folder. Then i created a new C::B proj using the wxWidgets path to the one on the desktop, and now the error is gone.
I don't 100% understand how wxWidgets works so I hope just copying the whole folder to another location is fine, but so far program seems to be working. Thanks

Multiple include paths (-I) for g++ in Eclipse and MinGW

I am using Eclipse Luna in a Windows environment to write programs in C++. I compile with MinGW. I am also using OpenCV and libxml2.
My programs get compiled with these include paths:
g++ "-IC:\\MinGW\\include\\libxml2" ...
However, I need include paths for libxml, so what I want is:
g++ "-IC:\\MinGW\\include\\ibxml2" "-IC:\\opencv\\build\\include"
I tried to set this up under "project | Propterities | Tool Settings | GCC C++ Compiler" in the project properties:
-I"C:\opencv\build\include" -I"C:\MinGW\include\libxml2" -O0 -g3 -Wall -c -fmessage-length=0 -v
However, it only puts the first one in the actual compile command, according to the console.
It does work sometimes, though:
If I "Clean" the project and the build it, it will build without errors and even run from Windows Explorer or a prompt.
If I try to Run or Debug it from Eclipse, it will fail and have the problems described above.
If I "Clean" it and Run or Debug it, it will run fine in the Debug perspective, but will terminate without warning.

Eclipse: Edit toolchain (remove build step to create a shared library for CUDA)

I am trying to configure Eclipse such that it compiles a shared library in one project and uses it in another.
The problem is, that using the CUDA plugin for Eclipse one can only choose an executable generating project type.
So what I want to do is creating such a project and modify that toolchain such that Eclipse does not execute anything else than nvcc.
As you can see compiling the library is not a problem:
18:27:25 **** Incremental Build of configuration Default for project cudamath ****
make all
Building file: ../test.cu
Invoking: CUDA NVCC Compiler
nvcc --shared -Xcompiler -fPIC -o "cu_test.o" "../test.cu" && \
echo -n 'cu_test.d' ./ > 'cu_test.d' && \
nvcc -M "../test.cu" >> 'cu_test.d'
nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
Finished building: ../test.cu
The problem is that Eclipse then calls g++ which is that step of the toolchain I want to cut off:
Building target: cudamath
Invoking: C++ Linker
g++ -L/opt/cuda/lib64 -o "cudamath" ./cu_test.o -lcuda -lcublas -lcudart
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../lib/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
makefile:32: recipe for target 'cudamath' failed
make: *** [cudamath] Error 1
Is there a way I can do this? I've been crawling through my project settings but I can't seem to find what I'm looking for.
Here's what I did using Nsight Eclipse Edition:
File... new CUDA C/C++ project
In the next dialog, select Shared Library...Empty Project, and give the project a name (let's say it is testlib)
Finish that wizard/dialog. A new testlib project is created in the project explorer on the left
In the project explorer on the left, right click on the project name and create a new folder for your source files
Open that folder and create your new source file. For this, I selected a CUDA C/C++ source file using the CUDA bitreverse "template". This creates a new source file with the bitreverse code in it.
change int main() { in your source file to int myfunc(){
save the source file and build the project. A new libtestlib.so is successfully built.

MinGW .exe requires a few gcc dll's regardless of the code?

When compiling with MinGW, I have to copy over certain dll files from the MinGW bin directory before the exe will run (Even when using "-static" and/or "-static-libstdc++".)
How do I change that? Is there a special build of MinGW that I have to use? Ultimately I want to be able to run the program with nothing but the exe in the directory (and no windows environment variables set.) These File's are:
libstdc++-6.dll
libgcc_s_seh-1.dll
libwinpthread-1.dll
And here is the complete list of step's I fallow:
Open Up Code::Blocks
Select "File->New->Project->Console"
Fill out the project settings for project "Hello World"
Right click Project->Build Options...->Hello World (Root target)->Other Options
Enter "-static" (or "-static-libstdc++") under the already set "-fexceptions"
CTRL-F9 : Build Project (Without executing)
Navigate to, in Windows Explorer, and run the built "Hello World.exe" file.
Click "OK" when a message pop's up saying "Error: libstdc++-6.dll is missing from your computer."
Copy "libstdc++-6.dll" from the /MinGW/bin/ directory, into the "Hello World.exe" directory.
Run "Hello World.exe"
Click "OK" for the message saying "Error: libgcc_s_seh-1.dll is missing from your computer."
Copy "libgcc_s_seh-1.dll" into the "Hello World.exe" directory.
Repeat and end up copying "libwinpthread-1.dll" over aswell.
View the message
Hello World!
Edit:
My command line is:
g++.exe -Wall -fexceptions -static -static-libgcc -static-libstdc++ -g -static-libgcc -static-libstdc++ -L. -c "C:\Users\______\Desktop\Hello World\main.cpp" -o obj\Debug\main.o
g++.exe -o "bin\Debug\Hello World.exe" obj\Debug\main.o
With all the dll files mentioned above required. And, just to be safe, the code is:
// main.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
Your commands are wrong !
Go to the directory where your main.cpp file is, and try the following.
g++.exe -Wall -c -g main.cpp -o obj\Debug\main.o
g++.exe -static -static-libgcc -static-libstdc++ -o "bin\Debug\Hello World.exe" obj\Debug\main.o
then you'll no longer need to copy the DLLs (for your Hello World program).
Other notes:
The MinGW installation instructions recommends setting
c:\minGW;c:\MinGW\bin;
to the PATH environment variable.
Normally the
-static -static-libgcc -static-libstdc++
linker options should work (try all 3 of them at once). But not for libwinpthread-1.dll.
Also, try to clean before recompiling.
There's no "-static-something" command.
Only standard libraries libgcc and libstdc++ can be set to static linking.
For other libraries, you first switch to static linking with "-static" and then list the libraries to include with separate commands, i.e. "-lpthread".
Cmake users should try adding:
set(CMAKE_CXX_STANDARD_LIBRARIES "-static-libgcc -static-libstdc++ -lwsock32 -lws2_32 ${CMAKE_CXX_STANDARD_LIBRARIES}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive")
-static-libgcc may be a bad idea if exceptions are used. link options documentation states that
There are several situations in which an application should use the
shared libgcc instead of the static version. The most common of these
is when the application wishes to throw and catch exceptions across
different shared libraries. In that case, each of the libraries as
well as the application itself should use the shared libgcc.
The comments to the answer above contain the full solution, so I would like to merely add the CodeBlocks perspective. I verified it on Windows7 x64 with CodeBlocks16 and MinGW-W64 8.1.0 ''i686-posix-dwarf''.
This solves the OPs question
Create new project and name it "Hello World"
accept all defaults in the wizard
select Project/BuildOptions/ and select "Hello World". Out edits will be valid for both Debug and Release
add the following at "Other linker option" in the "Linker" Tab
-static
-static-libgcc
-static-strc++
-lwinpthread
On the Toolbar select "Debug" and press Build (the yellow gear icon)
Press the green run icon and confirm that the build was ok
Testing
open a terminal window and go to the HelloWorld\bin\debug folder
start hello world there.
Confirm it works without asking for any DLLs.
You could also start it from an explorer window and confirm that it also does not ask for DLLs.
Note: On my Win7x64 system when starting the HelloWorld.exe from the explorer adding the "-lwinpthread" line causes CodeBlocks to ignore the setting in "Projects/Properties/Tab_BuildTargets/ "Pause when execution ends". So the "Hello World" output is hardly visible because the window immediately closes after execution (mabye someone knows why)
Note that if you do not have the winpthread.dll not found problem of the OP then you likely do not use a MinGW-W64 compiler with a 'posix' thread model. Both Code blocks MinGW-W64-bundled install packages use such versions. For CB20.03 the relevant downloads from MinGW-W64 download page would be
32bit: 8.1.0 ''i686-posix-dwarf''
64bit: 8.1.0 ''x86_64-posix-seh''
For example if I set setup compilers with Codeblocks direcly and chose the 32-bit compiler package ''i686-win32-dwarf'', only the first 2 DLLs would go missing. In that case the fix is to set the linker options only to
-static-libgcc
-static-strc++

Configure Eclipse CDT to use g++

I have cygwin installed, and I want to use Eclipse with CDT for development under Windows 7. However, I get following error:
**** Build of configuration Default for project hello_cpp ****
make all
g++ -O2 -g -Wall -fmessage-length=0 -c -o hello_cpp.o hello_cpp.cpp
process_begin: CreateProcess(C:\cygwin\bin\g++.exe, g++ -O2 -g -Wall -fmessage-length=0 -c -o hello_cpp.o hello_cpp.cpp, ...) failed.
make (e=5): Access denied.
make: *** [hello_cpp.o] Error 5
**** Build Finished ****
I'm able to use g++ as standalone compiler.
cygwin /bin folder is
added to path.
After googling I found out that C:\cygwin\bin\g++.exe is a cygwin symbolic link and Windows doesn't understand it and I need to point to the g++-3 location directly. How do I do it?
I think you've done something wrong and need to start over again. Just installed Cygwin and Eclipse CDT (Indigo) on my Windows 7 and all works fine and auto-magicaly for me.
Here's what I did and I think you need to do:
Get the latest Cygwin (yes, get it again! get rid of the old one just to be sure)
During the installation make sure to select gcc, gcc-g++ and make (I additionally installed couple of other things like gcc4, w32api but it's optional)
Start Cygwin terminal to init all configuration files, etc. See if g++ executes and close the terminal.
Add C:\cygwin\bin (or wherever else you installed it) to your Environment PATH variable
Get Eclipse CDT, extract it somewhere and start it up.
Go to File -> New Project -> C++ Project and select Hello World C++ Project. You should see the Cygwin GCC in the Toolchains list.
Create the Project, build and run it!
Done!
Build output:
**** Build of configuration Debug for project TestApp ****
make all
Building file: ../src/TestApp.cpp
Invoking: Cygwin C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/TestApp.d" -MT"src/TestApp.d" -o "src/TestApp.o" "../src/TestApp.cpp"
Finished building: ../src/TestApp.cpp
Building target: TestApp.exe
Invoking: Cygwin C++ Linker
g++ -o "TestApp.exe" ./src/TestApp.o
Finished building target: TestApp.exe
**** Build Finished ****
You can go to
Project Properties Page > C / C++ Build > Settings > Tool Settings
And change the command as you want. Documentation here.
Refer this link, it shows how to setup eclipse for native development with ease. everything is done in eclipse except setting environment variables.