Include mingw libraries in compiled file - gcc

I am using cmake to generate a Eclipse CDT MinGW Project. (Eclipse Version Kepler)
This is my Cmakelist:
project(IMGTODICOM)
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
add_executable(IMGTODICOM IMGTODICOM.cxx)
target_link_libraries(IMGTODICOM ITKReview ${ITK_LIBRARIES})
The code compile and run without problem in my computer, but in other PC it does not run. Some dll like libgcc_s_dw2-1.dll are required. I looked for this dll in my computer and I found it in C:\MinGW\bin. To solve the problem I copied the content of this folder in the other PC and the exe file finally run.
However, I am wondering if there is a better method to run the exe file in any windows pc adding these libraries in the compilation process.
I was reading and I should make that the compiler link to a static library. In Eclipse I tried to add the dll under properties>C/C++ Include Path and Symbols and under project Path>Libraries, but it does not work. I tried to modify the CmakeList but it also does not work.
I don't know why this problem and how can I include the content of C:\MinGW\bin in the exe file.
Many Thanks for any help

Yes, there is a way. For pure C code:
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static")
For C++ code:
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")

Related

CUDA: Modifying CMake causes linking error

I had a CMake project. In order to use some cuda kernels in the project, i tried to first changed the name of mian.c to main.cu.
When i cmake the project, the Makefile is generated fine but when i try to build the project using make, the building process prompt me following:
main.cu: undefined reference to <ftns>
The building process works perfectly fine when i modify the main.cu to main.c
The issue was resolved.
The extension of the main was .cu and the which it was directly calling were in .c extensions. So i also changed the extension of those files to .cu and it worked.

Why does OMNet++ compiler gets errors for a precompiled package?

I have included an external package callled SoPlex (a folder of .cpp and .h files and the library files) into my OMNet++ project. I have already tested the package in Code::Blocks IDE and it works fine besides some warnings it had: warning: explicit conversion operators only available with -std=c++11 or -std=gnu++11.
It certainly was working in Code::Blocks IDE. But when I want to use it in my OMNet++ project it gives a lot of errors for the SoPlex package like in the picture:
It gives a lot of errors for just the code of SoPlex and not my OMNet++ project code.
Any idea what may cause the problem?
I have used MinGW to compile SoPlex package in Code::Blocks IDE. When I use MinGW GCC in OMNet++ instead of GCC for OMNet++ as current toolchain there is this error fatal error: omnetpp.h: No such file or directory.
Regarding the errors with the 3rd party library. Depending where you put the library inside the src folder, at least that directory must be added as an include dir, otherwise the header files will not be found by the compiler.
As for the problem with the omnetpp.h: OMNeT++ has it's own makefile generator which automatically adds the required include folder (omnetpp_root/include). The generic MinGW GCC toolchain does not. If you want to avoid extra work, always use the omnet toolchain to build your models.

Build dynamic windows library (DLL) from libmcrypt with MinGW

I'm trying to build libmcrypt library to use it with my project. It happened so, that they do not provide any kind of assistance.
First I've faced a problem with -no-undefined flag for gcc which is not further supported. I've replaced -no-undefined with -Wl,-no-undefined in makefiles and it does the trick.
But anyway I'am having problems. Lib is builded in .a files. I can see them in my C:\MinGW\msys\1.0\local\lib folder (it is analogue for /usr/local/lib folder in MinGW). But I need .dll library, not static .a .
So: what else must I change in makefiles to make MinGW build dll with header and debug info for it?

Error in CodeBlocks C++ program and how to set default main class

I have included the boost library in a Codeblocks c++ project.
Now, in the file
boost/function.hpp
there is an include statement
#include <boost/preprocessor/iterate.hpp>
However I get this error in Codeblocks when I try and compile:
/home/arvind/Documents/Workspace/Browser/boost/function.hpp|15|fatal error:
boost/preprocessor/iterate.hpp: No such file or directory|
What am I doing wrong here? I have simply included the Boost library as it is.
Also, I cannot find the screen/option to set the main class (which will actually execute).
How do I do this?(I am new to CodeBlocks hence this question).
Your boost includes seem to be in a non-standard/system directory : /home/arvind/Documents/Workspace/Browser, you must tell the compiler to look there (gcc -I command-line switch).
Go to Project->Build Options->Search Directories->Compiler and add the directory where boost includes are. I don't have a codeblocks install right here so this was from here.
If you can, I would recommand installing boost on your system once and for all instead of just copying files in your codeblocks workspace.

dev cpp win32 the program can't start because sqlite3.dll is missing

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).

Resources