Well, that's it. I'm sure the title is descriptive enough.
I'm trying to compile a hello world sort of application I wrote in C++ with wxWidgets.
I have four files, let's call them frame1.h, frame1.cpp, main.h and main.cpp.
I just need a simple (if possible) method to compile the application from the cmd prompt,
preferably from a .bat script file.
I googled it, but everything I found was about compiling the wxWidgets library, which I already did, or compiling applications with Visual Studio or other IDEs like Code::Blocks. I just want to do it from the command prompt with MinGW. I found a method that used back ticks but those aren't supported in Windows and I don't even know if it would work even if there was a workaround of some sort.
I know asking for a step by step method would be too pretentious but it would be very appreciated. Of course, I know that might not be possible, but I doubt compiling an application can be rocket science and probably I'm just missing something very obvious cause I'm stupid.
EDIT: I compile my applications like this...
g++ -Wall -c -o ClassFile.o ClassFile.cpp
g++ -Wall -o Program.exe ClassFile.o main.cpp
...for example. I'm looking for a similar method to compile wxWidget apps.
Well, thank you.
Good luck.
If you've already compiled wxWidgets successfully, go to the samples/minimal subdirectory and type make -f makefile.gcc -n. This will show you the commands used to build the minimal sample, including all wxWidgets-specific options you must use for both the compilation and link commands. Unfortunately, if you use cmd.exe your only solution is to manually copy-paste these options in another window (replacing "minimal" with your program name, of course) as, as you already know, it doesn't support the command substitution (backticks) mechanism.
As this gets tiresome pretty quickly, the usual thing to do is to write a makefile, even if it's just a very simple one, where these options are defined in variables that are then reused for all files.
I have created a video on this topic https://www.youtube.com/watch?v=f6FDNR3lh8E
Here is small and simple steps to follow.
Pre-Requirements :
GNU g++ compiler downloaded and installed.
Set gcc/g++ path to Enviroment Variable.
Download WxWidgets Binaries : 1. Header Files, 2. Development Files, 3. DLLs.
Extract then one folder as it is. I have extracted them at D:\WxAPI Folder.
Looks Like :
D:
- WxAPI Folder
- include (Header files has this folder ziped in .7z)
- lib (Development Files & DLL has this folder ziped in .7z and both extracts in this save folder)
Set your project development structure.
My Project Development Structure :
WxExample (Project Folder)
- Build (Folder) : Contains debug and release dlls and exe
- debug (Folder) : Contains debug specific dlls and exe.
- release (Folder) : Contains release specific dlls and exe.
- inlcude (Folder) : Contains project header files.
- src (Folder) : Contains project .cpp files.
- wxCompiler.cmd : Contains compile command created with following steps.
Write Compilation Command
Link Following to Compile.
First Compile Project *.cpp Files :
g++ ".\src*.cpp"
Give Project Output .exe Name :
-o ".\build\release\Project_Name.exe"
Show Project .h File Location to g++ :
-I ".\include"
Provide WxWidget .h Files :
-I "D:\WxAPI\include"
Locate WxWidget setup.h File :
-I "D:\WxAPI\lib\gcc810_x64_dll\mswu"
Supply Binaries Location of WxWidgets :
-L "D:\WxAPI\lib\gcc810_x64_dll"
Provide Compile Flags :
-l wxbase31u
-l wxmsw31u_core
Here D:\WxAPI\lib\gcc810_x64_dll\libwxbase31u.a File Renamed To "wxbase31u"
& D:\WxAPI\lib\gcc810_x64_dll\libwxmsw31u_core.a File Renamed To "wxmsw31u_core" as flag.
You have to add similar file flag as you used in your project as .h
For Example :
-lwxmsw31u_core -lwxbase31u -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregexu -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lshlwapi -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lversion -lwsock32 -lwininet -loleacc -luxtheme
Here is Full Command :
g++ ".\src*.cpp" -o ".\build\release" -I "D:\WxExample\include" -I "D:\WxAPI\include" -I "D:\WxAPI\lib\gcc810_x64_dll\mswu" -L "D:\WxAPI\lib\gcc810_x64_dll" -l wxbase31u -l wxmsw31u_core
Run wxWidgets.cmd and that's it. Your exe is in your .\Build\release folder.
Set WxWidget DLL path in Enviroment Variable.
If you do not want to copy paste required dll to your release/debug folder.
Related
I'm analyzing a CMake project and I want to get all the header files that a source file depends on. Is there a tool or a command like gcc -M or g++ -M to list all the dependencies of one file in the CMake project? It would be better if I could also get which Target each header file belongs to.
Of course I can’t use g++ -M directly because it can’t find some dependencies organized by CMakeLists.txt.
Since the cmake command will generate MakeFile, a tool or command for Make may may also work for me.
Check the build folder for your CMake project. For each target, CMake should generate a file called C.includecache. This file contains the include dependency information.
If, for example, you have a main.c file which is including the stdio.h and math.h headers. The C.includecache file will contain an entry like:
/path/to/main.c
stdio.h
-
math.h
-
I'm making a 3D printer from scratch, hardware and software. I am using mingw to compile on windows and it works. But the .exe it produces relies on a bunch of .dlls in mingw's bin folder. So that means that either I'm doing something wrong or just don't know which .dlls need to go with my .exe.
The command I run to compile is:
g++ -o Slicer.exe "d:\Programming And Creativity\Slicer\main.cpp" "d:\Programming And Creativity\Slicer\slice.cpp" "d:\Programming And Creativity\Slicer\face.cpp" "d:\Programming And Creativity\Slicer\line.cpp" "d:\Programming And Creativity\Slicer\vertex.cpp"
If I try going to my project's folder and running g++ from there, it complains about a bunch of missing files. How can I reduce the numer of dll's needed to run the exe file?
I figured out a solution to my problem, I just had to add the --static flag.
I have a problem with PCL: specifically I want to use it in the existing project with existing Makefiles. However, PCL is using CMake and I couldn't find how to add it to Makefile directly. Does anyone know how to do that?
First try to compile the one of the example provided in PCL website using CMake.
http://pointclouds.org/documentation/tutorials/pcl_visualizer.php
After compiling the above example, you will find various new files and a folder created by CMake in your directory.
Go to CMakeFiles/pcl_visualizer_demo.dir/ .
Open file named link.txt, which contains the terminal command which has various pcl(point cloud libraries) linked dynamically to the file.
command should look similar to the command shown below
/usr/bin/c++ -O3 -Wno-deprecated -s CMakeFiles/pcl_visualizer_demo.dir -o pcl_visualizer_demo -rdynamic -lpcl_common -Wl,-Bstatic -lflann_cpp_s -Wl,-Bdynamic -lpcl_kdtree -lpcl_octree -lpcl_search -lqhull -lpcl_surface -lpcl_sample_consensus -lpcl_io -lpcl_filters -lpcl_features -lpcl_keypoints -lpcl_registration -lpcl_segmentation -lpcl_recognition -lpcl_visualization -lpcl_people -lpcl_outofcore -lpcl_tracking /usr/lib/libvtkGenericFiltering.so.5.8.0 /usr/lib/libvtkGeovis.so.5.8.0 /usr/lib/libvtkCharts.so.5.8.0 /usr/lib/libvtkViews.so.5.8.0 /usr/lib/libvtkInfovis.so.5.8.0 /usr/lib/libvtkWidgets.so.5.8.0
You can include these libraries in your Makefile directly.
If you use different functions or pcl headers files, then first try compiling it using CMake and get the libraries linked and add it to your Makefile of previous project.
I tried this method for my project which worked perfectly fine. I tried pkg-config to link the libraries, which didn't work in my case. I was not able to find any other method that easily links all the required libraries.
I am using dev c++ IDE which used ming gcc(i am not sure of it)
I wanted to use sqlite3 in my win32 c application
I downloaded sqlite3.dll and sqlite3.dev and used dlltool to create a .a file like libsqlite3.a and pasted in the lib folder of dev cpp and added this path in the project options -> parameters
i copied the header file sqlite3.h into the include folder(which i got from another website - http://www.opensource.apple.com/source/SQLite/SQLite-74/derived_source/sqlite3.h)
i executed the program and got the message 'the program can't start because sqlite3.dll is missing in your computer'
so i copied the sqlite3.dll into my working directory and then it worked
BUT
How to make the sqlite.* static while compiling?
I mean i thought by including the libsqlite3.a, the final exe will not be dependent of any external dll's.
So i want to know how to compile in a way that i will not be needing a dll and by doing so it makes my windows program standalone.
do i have a create a .lib file instead of .a file?
EDIT after answers and comments:
Besides, the devpak is working fine... yet i wanted to know how to include files to project or to create .a files so i am trying this way because if some components do not provide devpak then this will be the way we need to compile.. isn't it?
EDIT to show what i have done after the answer by CL and the two comments
This is how i have added the sqlite.c to project list
Here is the compile log
Compiler: Default compiler
Building Makefile:
"C:\Users\jayapalc\Documents\test-sqlite\Makefile.win"
Executing make...
make.exe -f "C:\Users\jayapalc\Documents\test-sqlite\Makefile.win" all
g++.exe -c sqlite3.c -o sqlite3.o -I"lib/gcc/mingw32/3.4.2/include"
-I"include/c++/3.4.2/backward" -I"include/c++/3.4.2/mingw32" -I"include/c++/3.4.2" -I"include"
sqlite3.c: In function `void strftimeFunc(sqlite3_context*, int,
sqlite3_value**)':
sqlite3.c:14727: error: invalid conversion from void*' tochar*'
The files i got in sqlite.org/sqlite-amalgamation-3071502.zip are
shell.c, sqlite3.h, sqlite3.c, sqlite3ext.h and i saw in other discussions that shell.c is not needed...
Besides, people were talking about gcc and g++... .
Apart from updating Dev-C++ itself, try this to compile sqlite.c as a C file:
Go to Project >> Project Options >> Files.
Find the C file we're talking about. Untick "Compile file as C++".
This should inform Dev-C++ that it should invoke gcc.exe, and not g++.exe.
If you don't want to compile sqlite yourself by adding it to your project, you can try passing the -static flag to GCC/G++ to force it to link libsqlite.a statically.
Just include the sqlite3.c file in your project.
You need only this filed, and it must be compiled as C, not C++.
Apparently, Dev-C++ does not allow mixing C and C++ source files in one project.
Instead, you could try to compile sqlite3.c as C and then include the generated .o file into the C++ project (on the Linker page).
I have compiled gdc together with gcc using the android build-gcc.sh script, and have included a new stub in build/core/definitions.mk to deal with D language files as a part of the build process. I know things are compiling OK at this point, but my problem is linking:
When I build a project, I get this error:
ld: crtbegin_so.o: No such file: No such file or directory
This is true for regular c-only projects as well. Now I ran a quick find in my build directory, and found that the file (crtbegin_so.o) does exist within the sysroot I specified when I compiled gcc (or rather, when build-gcc.sh built it).
What are some things I could look for to find a solution to this problem?
Would copying the files locally and linking directly to them be a decent solution in the
interim?
Why would ld (or collect2) be trying to include these for a gdc (D Language) linkage?
The issue arises on NDK r7c for linux as well.
I found that the toolchain ignores the platform location ($NDK_ROOT/platforms/android-8/arch-arm/usr/lib/) and searches for it in the toolchain path, which is incorrect.
However, as the toolchain also searches for the file in the current directory, one solution is to symlink the correct platform crtbegin_so.o and crtend_so.o into the source directory:
cd src && ln -s NDK_ROOT/platforms/android-8/arch-arm/usr/lib/crtbegin_so.a
cd src && ln -s NDK_ROOT/platforms/android-8/arch-arm/usr/lib/crtend_so.a
Thus your second point should work out (where you can do a symlink, instead of a copy)
NOTE 1:This assumes that the code is being compiled for API8 (Android 2.2) using the NDK. Please alter the path to the correct path as per your requirement.
NOTE 2:Configure flags used:
./configure \
--host=arm-linux-androideabi \
CC=arm-linux-androideabi-gcc \
CPPFLAGS="-I$NDK_ROOT/platforms/android-8/arch-arm/usr/include/" \
CFLAGS="-nostdlib" \
LDFLAGS="-Wl,-rpath-link=$NDK_ROOT/platforms/android-8/arch-arm/usr/lib/ -L$NDK_ROOT/platforms/android-8/arch-arm/usr/lib/" \
LIBS="-lc"
I have found that adding --sysroot=$(SYSROOT) to the compiler options fixes the error:
cannot open crtbegin_so.o: No such file or directory
from my makefile...
CC= $(CROSS_COMPILE)gcc -fvisibility-hidded $(INC) $(LIB) -shared
Note: this assumes that the setenv-android.sh has been run to setup the environment
$. ./setenv-android.sh
In my case quotes were missing from sysroot path.
When I changed
--sysroot=${ANDROID_NDK}\platforms\android-17\arch-arm
to
--sysroot="${ANDROID_NDK}\platforms\android-17\arch-arm"
the project was compiled and linked successfully.
I faced with the same issue in two separate cases:
during building boost for android
during using android-cmake project.
Once I have switched to standalone toolchain issue gone, here is example of command which prepare standalone toolchain
$NDK_ROOT/build/tools/make-standalone-toolchain.sh --platform=android-9 --install-dir=android-toolchain --ndk-dir=$NDK_ROOT --system=darwin-x86_64 --toolchain=arm-linux-androideabi-4.9
Boost specific
for boost you need specify --sysroot several times in your jam
<compileflags>--sysroot=$NDK_ROOT/platforms/android-9/arch-arm
<linkflags>--sysroot=$NDK_ROOT/platforms/android-9/arch-arm