How to add a library include path for NetBeans and gcc on Windows? - c++

How to add a library include path for NetBeans and gcc on Windows?
Using:
NetBeans 7.1.2
MinGW (mingw-get-inst-20120426.exe)
gcc 4.7.0

For example, you want to add the directories in C:\Program Files (x86)\Example\1.0\include\ as the include paths.
First, set up code assistance:
NetBeans > Tools > Options > C/C++ > Code Assistance
C Compiler > Include Directories:
C:\Program Files (x86)\Example\1.0\include\shared
C:\Program Files (x86)\Example\1.0\include\other
C:\Program Files (x86)\Example\1.0\include
C:\MinGW\lib\gcc\mingw32\4.7.0\include
C:\MinGW\include
C:\MinGW\lib\gcc\mingw32\4.7.0\include-fixed
...
C++ Compiler > Include Directories:
C:\Program Files (x86)\Example\1.0\include\shared
C:\Program Files (x86)\Example\1.0\include\other
C:\Program Files (x86)\Example\1.0\include
C:\MinGW\lib\gcc\mingw32\4.7.0\include\c++
C:\MinGW\lib\gcc\mingw32\4.7.0\include\c++\mingw32
C:\MinGW\lib\gcc\mingw32\4.7.0\include\c++\backward
C:\MinGW\lib\gcc\mingw32\4.7.0\include
C:\MinGW\include
C:\MinGW\lib\gcc\mingw32\4.7.0\include-fixed
...
OK.
The C:\MinGW\... directories are examples only. Do not actually add them. NetBeans should have detected and added the MinGW directories automatically. If not, try resetting the settings:
NetBeans > Tools > Options > C/C++
Code Assistance
C Compiler > Reset Settings
C++ Compiler > Reset Settings
Build Tools
Restore Defaults
For instructions on automatic code assistance for existing sources, see:
C/C++ Projects Quick Start Tutorial:
http://netbeans.org/kb/docs/cnd/quickstart.html#makefileprojects
How to Configure Code Assistance When Creating a Project from Existing Code:
http://netbeans.org/kb/docs/cnd/configuring-code-assistance.html
Now, configure the project options:
Right click on project > Properties
Configuration: <All Configurations>
Build
C Compiler
General
Include Directories:
C:\Program Files (x86)\Example\1.0\include\shared
C:\Program Files (x86)\Example\1.0\include\other
C:\Program Files (x86)\Example\1.0\include
Compilation Line
Additional Options:
-std=c11 -g3 -pedantic -Wall -Wextra -O0
C++ Compiler
General
Include Directories:
C:\Program Files (x86)\Example\1.0\include\shared
C:\Program Files (x86)\Example\1.0\include\other
C:\Program Files (x86)\Example\1.0\include
Compilation Line
Additional Options:
-std=c++11 -g3 -pedantic -Wall -Wextra -O0
OK.
For adding command-line options by default for all projects, see:
NetBeans settings for GCC
Any spaces in the path should be automatically escaped. Any backward slashes should be replaced with forward slashes automatically.
For example, the "All options" textbox in "Additional Options" looks like this:
-std=c11 -g3 -pedantic -Wall -Wextra -O0 -g -I/C/Program\ Files\ \(x86\)/Example/1.0/include/shared -I/C/Program\ Files\ \(x86\)/Example/1.0/include/other -I/C/Program\ Files\ \(x86\)/Example/1.0/include
If this does not work, you may have to fix the path and add the includes manually in the additional options. For example, replace /C/ with C:/.
-std=c11 -g3 -pedantic -Wall -Wextra -O0 -g -IC:/Program\ Files\ \(x86\)/Example/1.0/include/shared -IC:/Program\ Files\ \(x86\)/Example/1.0/include/other -IC:/Program\ Files\ \(x86\)/Example/1.0/include
If you are using Cygwin make and if you try to clean or rebuild the project with colons in the command, you may get a *** multiple target patterns. Stop. error message. According to the answers from Multiple target patterns? and Very simple application fails with "multiple target patterns" from Eclipse, "make sees the : in the path and thinks it is another target definition, hence the error."
The workaround is to delete the generated build and dist folders every time before you build your project. However, this can be annoying, so you could try MinGW MSYS make instead (not to be confused with MinGW make, which is unsupported).
For MinGW and MSYS configuration instructions, see:
Configuring the NetBeans IDE for C/C++/Fortran:
http://netbeans.org/community/releases/68/cpp-setup-instructions.html#mingw
For working with MinGW and Unicode, you should install the latest version of MinGW-w64. See:
wWinmain, Unicode, and Mingw

Related

Clang 4.0 debugging using Visual Studio

I have a project that I am still trying to setup using Clang and Visual Studio on Windows. As a caveat, I've worked on several c++ projects but they've all been mature projects where I haven't had to be involved in setting up make files or resolving dependencies hence why I want some experience in doing so.
As a clarification, I am not using the LLVM built into visual studio thing. My goal was to have visual studio be a convenience on top of having a project that can be built with make files but not using CMake.
So far, I have a solution with a single nmake project. This nmake project calls a build.bat file which calls into a make file. This make file looks like this:
# Based on PUXAN tutorial
# http://www.puxan.com/web/howto-write-generic-makefiles/
# Compiler choice
CC = clang++ -g -O0
CC_OBJ_FLAGS = -w -v -c
# Name of our executable and also the main run target
EXEC = ../bin/output.exe
# Here we get every cpp file in the source directory to make a list of source files
SOURCES = $(wildcard ../src/*.cpp)
# Here we have mapped all the cpp files to o files and now have a list of o files
TMP_OBJECTS = $(SOURCES:.cpp=.o)
OBJECTS = $(foreach obj,$(TMP_OBJECTS),$(subst src,obj,$(obj)))
INC = -I../lib/glfw-3.2.1/include
LINK = -L../lib/glfw-3.2.1/lib-vc2015 -lglfw3dll -lglfw3 -lopengl32
# compile list of o files into executable
# NOTE: when make is run without a target, the first target is chosen. This target
# should remain the first at all times
$(EXEC): $(OBJECTS)
$(CC) $(LINK) $(OBJECTS) -o $(EXEC)
# As each o file becomes a target, compile the associated cpp file into the o file
../obj/%.o: ../src/%.cpp
$(CC) $(CC_OBJ_FLAGS) $(INC) $< -o $#
# Remove the entire list of objects and the executable
clean:
rm -f $(EXEC) $(OBJECTS)
rebuild:
make -B
You'll notice that I've included the -g and -O0 flags which should output symbols and sure enough, I get a pdb file generated for output.exe (and also all the o files but I can clean that up later). When I go to debug the project in Visual Studio however, it says the symbols for the module are loaded but breakpoints aren't hitting which I think is pointing to the pdb not having references to the source. Here is the debug output in Visual Studio:
'output.exe' (Win32): Loaded 'W:\Scratch\Engine\bin\output.exe'. Symbols loaded.
Posts about Clang from 2016 and earlier mention that it doesn't generate PDB files yet and that thats a work in progress and sure enough the Clang compability site (https://clang.llvm.org/docs/MSVCCompatibility.html) mentions how debug info is a work in progress but that I should be able to generate CodeView info using /Z with 7 or i. I have tried passing both /Zi and /Z7 to clang and to the linker directly but clang complains about them and the linker ignores them with a warning. This documentation claims to be from Clang 6 that is, from what I can tell, not released yet and is experimental. However, using Clang 4.0 with -g flag, I am indeed able to generate pdb files.
Does anyone have any further information on this? Is there anything else I can provide to determine if I have set all this up correctly? Am I just missing a flag that would correctly provide the sources or am I missing a setting in visual studio to pick the sources? I tried setting sources manually in visual studio at the project and solution level to no effect. Should I look at the pdb file with a pdb viewer of some kind and see if the source paths are there?
Thanks in advance to any help.
The clang option equivalent to -Z7/-Zi is called -gcodeview (and has to be used in addition to -g). For MSVC-style command line options, you need to use the clang-cl compiler driver instead.
For the MSVC Version ( https://llvm.org/builds/) it works like in the following picture but to set clang on VS2017 up you need to install Microsoft's Platform Toolset V1.40 first:
VS2017 Clang debug
Project -> Properties -> C/C++ -> Commandline -> Options: "/Z7"

Get Error When Compile Source (.C) file Using Microsoft Visual C/C++ compiler via GnuWin32 in Windows 7

I will show you step as below ....
First You Download GNUWIN32.
Then Install on windows 7 and Set Environment Path.
I will make a.C Source file shown as below
#include <stdio.h>
int main()
{
//FileName: a.C
printf("Hello World !!! Its works");
return 0;
}
I will to make Makefile. shown as below
#MakeFile Source Code... FileName: Makefile
OBJS: a
#add path visual c/c++ compiler
PATH=C:/Program Files\ (x86)\Microsoft\ Visual\ Studio\ 9.0/VC
CC: $(PATH)/bin/cl.exe
all: a
a:
$(CC) -c a.C
clean:
rm -rf $(OBJS)
I compile Source code. it get error.
Input: C:\Users\*****\Desktop\Test>make
output:
cc -c a.C
process_begin: CreateProcess(NULL, cc -c a.C, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [a] Error 2
Please Let Me help, How to build this code using visual c++ compiler.
PATH is the wrong name to use for a variable in your Makefile, because it is also the name of the variable that lists the paths to be searched when looking for other programs. Change it to something else.
There's a semantic error in your makefile. You are defining CC as a target, not a variable. Fix it thus:
CC=$(PATH)/bin/cl.exe
The clue is in the error message process_begin: CreateProcess(NULL, cc -c a.C, ...) failed.. You can see that it's trying to execute cc not cl.exe
If you have a look at vcvars32.bat, provided by μSoft to set up your environment for the compiler, you will see that it adds several folders to your %PATH% environment variable.
You can express this %PATH% minging in make if you want to. Something like
export PATH := /cygdrive/c/Program Files/Microsoft Visual Studio 9.0/Common7/IDE:/cygdrive/c/Program Files/Microsoft Visual Studio 9.0/VC/BIN:/cygdrive/c/Program Files/Microsoft Visual Studio 9.0/Common7/Tools:/cygdrive/c/Program Files/Microsoft Visual Studio 9.0/VC/VCPackages:/cygdrive/c/Program Files/Microsoft SDKs/Windows/v6.0A/bin:${PATH}:/cygdrive/C/PROGRA~1/MICROS~2.0/VC/redist/DEBUG_~1/x86/MICROS~1.DEB
Yes, this is make syntax. It augments any existing %PATH% with a prefix and a suffix (see that ${PATH} right in the middle?).
Note though that this is in a format ready for cygwin make. You may need a few adjustments. Oh, and don't forget that cl.exe needs decent settings for %INCLUDE%, %LIB% and %LIBPATH% too.

QT5 attaching project name with every sourcefile name, compiling error

i want to get started with QT. I donwloaded QT5 MINGW compiler with QT creator and i am trying to build the pre attached example named affine the problem is that the QT5 i think embed the project name with each of source file and thus gives error that file not found. some thing similar
:-1: error: ..affinemain.cpp: No such file or directory
while the file name is just
main.cpp
i don't know how to fix it. I searched lot on internet but could not found anything useful.
I even try to compile from command prompt but i am not fimmiliar with command prompt compiling as i am new to QT and previously i am totally developed with IDE in visual studio and eclipse for java so i have no idea about the make file and compiler command line arguments.
could some body please help me to fix this issue and can you tell please why compiler attaching project name with the source file name?
Thanks in advance
I have got the same problem and my solution may help you.
I am working with Qt5.0.1 now, and there are two distributions to work on windows with it: Qt5.0.1-mingw and Qt5.0.1-msvc2010.
I had to use mingw and there was a problem on my setup that "/" is ignored in path's.
So according to Qt Creator, compiler was called to process file mainwindow.cpp and this file was passed to it
g++ /*truncated*/ ..\qt-example\mainwindow.cpp
Below is the full compiler input:
g++ -c -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_OPENGL_ES_2 -DQT_OPENGL_ES_2_ANGLE -DQT_NEEDS_QMAIN -I..\qt-example -I"..\..\..\..\..\..\Qt\Qt5.0.1\5.0.1\mingw47_32\include" -I"..\..\..\..\..\..\Qt\Qt5.0.1\5.0.1\mingw47_32\include\QtWidgets" -I"..\..\..\..\..\..\Qt\Qt5.0.1\5.0.1\mingw47_32\include\QtGui" -I"..\..\..\..\..\..\Qt\Qt5.0.1\5.0.1\mingw47_32\include\QtCore" -I"debug" -I"." -I"." -I"..\..\..\..\..\..\Qt\Qt5.0.1\5.0.1\mingw47_32\mkspecs\win32-g++" -o debug\mainwindow.o ..\qt-example\mainwindow.cpp
And the error produced.
g++.exe: error: ..qt-examplemainwindow.cpp: No such file or directory
g++.exe: fatal error: no input files
compilation terminated.
So, we can see that "\" is ignored by the compiler and file name is merged with directory name.
The solution to that problem goes to the tools that are used - MinGW (Minimalist ports of GCC and Binutils). And also MSYS - a collection of GNU utilities such as bash, make, gawk and grep to allow building of applications and programs which depend on traditionally UNIX tools to be present. In our case - g++.
MSYS is not shipped with Qt5.0.1-mingw and g++ is not using it, but having MSYS available in your PATH environment variable breaks the system.
MSYS is used for git scm, which I have installed, so my path contains links to MSYS that goes bundled with git. So I have next paths in my PATH environment variable.
C:\Program Files (x86)\git\bin;C:\Program Files (x86)\git\cmd
I have not found how MSYS is used by Qt Creator or g++, or where it is linked, but when I have dropped next path from PATH:
C:\Program Files (x86)\git\bin;
and restarted Qt Creator - g++ succeeded on compiling my file, it worked.
The question why/how it influences the Qt Creator/g++ that should not use MSYS utils installed with git is still open.
i can´t comment.
important : delete all the files in the release and debug folder (compiled version) before try the tips of the autor ...

I can't even get the wxWidgets samples to compile using a

So I have been trying to get even just the damn samples for wxWidgets to compile with Mingw and I did like so mingw32-make -f makefile.gcc and I get the following error.
I do not have MSYS installed, and I have the latest version of Mingw
g++ -c -o gcc_mswud\minimal_minimal.o -g -O0 -mthreads -DHAVE_W32API_H -D__WXMS
W__ -D_UNICODE -I.\..\..\lib\gcc_lib\mswud -I.\..\..\include -W -Wall -I
. -I.\..\..\samples -DNOPCH -Wno-ctor-dtor-privacy -MTgcc_mswud\minimal_min
imal.o -MFgcc_mswud\minimal_minimal.o.d -MD -MP minimal.cpp
In file included from .\..\..\include/wx/defs.h:26:0,
from .\..\..\include/wx/wxprec.h:13,
from minimal.cpp:21:
.\..\..\include/wx/platform.h:256:22: fatal error: wx/setup.h: No such file or d
irectory
compilation terminated.
mingw32-make: *** [gcc_mswud\minimal_minimal.o] Error 1'
Any advice would be greatly appreciated
Also how exactly should I be compiling my own projects involving wxWidgets, what do I need to link against wxWidgets in mingw?
wx/setup.h is a file that is created during the compilation process; this file will be different for each different build type (Unicode, ANSI, Debug or Release, etc.). Most likely you compiled wxWidgets for one build type and are trying to compile the samples for a different build type.
As for the include / linker paths I have found the settings below to the bare minimum required to use wxWidgets in your own projects on Windows:
Include Paths
$(WXWIN)\include
$(WXWIN)\lib\vc_lib\mswud (u = Unicode and d=debug, this changes depending on what build type you want)
Pre-processor Definitions
WIN32
_DEBUG (only if you want to build with debugging info)
_WINDOWS
Character Set
"Use Unicode Character Set" (very important for Unicode builds; otherwise you will get compiler errors)
Additional Library Directories
$(WXWIN)\lib\vc_lib
Additional Dependencies
winmm.lib
comctl32.lib
rpcrt4.lib
wsock32.lib
odbc32.lib
wxmsw28ud_core.lib
wxbase28ud.lib
wxexpatd.lib
wxjpegd.lib
wxpngd.lib
wxregexud.lib
wxtiffd.lib
wxzlibd.lib
wxmsw28ud_adv.lib
wxmsw28ud_aui.lib
wxmsw28ud_html.lib
wxWidgets libraries are post-fixed with "u" for Unicode and "d" for debug, you need to choose the libraries that match the build type you want. $(WXWIN) is the directory where you built wxWidgets (wxPack will create this environment variable for you to use).

Missing Python.h while trying to compile a C extension module

I'm following this tutorial on how to extend Python with C\C++ code.
The section named "Building the extension module with GCC for Microsoft Windows" fails for me with the following error:
fatal error: Python.h: No such file or directory
The section named "Building the extension module using Microsoft Visual C++" also fails with a similar error:
fatal error C1083: Cannot open include file: 'Python.h': No such file or directory
What should I do to solve this?
For Linux, Ubuntu users to resolve the issue of missing Python.h while compiling, simply run the following command in your terminal to install the development package of python:
In Terminal: sudo apt-get install python-dev
Good luck
Do you have the python dev files so that you can find Python.h?
Do you have the location of Python.h specified to your compiler? with gcc this is usually done through a -I path to include.
Figuring out which of those is failing will solve your problem.
from the article you linked:
gcc -c hellomodule.c -I/PythonXY/include
gcc -shared hellomodule.o -L/PythonXY/libs -lpythonXY -o hello.dll
They assumed you installed python in the default location c:\pythonXY(Where X is the major version number and Y is the minor version number).(in your case Python26) If you put python somewhere else replace /PythonXY with where ever you installed it.
The Python official documentation has already made it clear. Check it out here
The header files are typically installed with Python. On Unix, these are located in the directories prefix/include/pythonversion/ and exec_prefix/include/pythonversion/, where prefix and exec_prefix are defined by the corresponding parameters to Python’s configure script and version is '%d.%d' % sys.version_info[:2]. On Windows, the headers are installed in prefix/include, where prefix is the installation directory specified to the installer.
To include the headers, place both directories (if different) on your compiler’s search path for includes. Do not place the parent directories on the search path and then use #include ; this will break on multi-platform builds since the platform independent headers under prefix include the platform specific headers from exec_prefix.
And they have provided a convenient way to get the correct cflags that we should pass to compiler. here
So for example, here is what I got after running the command
root#36fd2072c90a:/# /usr/bin/python3-config --cflags
-I/usr/include/python3.5m -I/usr/include/python3.5m -Wno-unused-result -Wsign-compare -g -fstack-protector-strong -Wformat -Werror=format-security -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes
Pass those flags to the compiler, and it will work.