Visual Studio Community 2017 cl linker won't link GTK3 libraries? - c

I am writing code in C using GTK as GUI toolbox. I installed GTK3 via MSYS2 and managed to compile and build using GCC (TDM-Dragon) alright.
However, lately I am trying to compile and link using cl included in Visual Studio Community 2017 (heard it is faster and more stable). With this, I am having a hard time building an application. I am loosely following this tutorial:
http://www.tarnyko.net/en/?q=node/22
I created a BAT file and invoke it from the VS 2017 command prompt:
set GINC_PATH="C:\msys64\mingw64\include"
set GLIB_PATH="C:\msys64\mingw64\lib"
cl gtk3test.c -I"%GINC_PATH%\gtk-3.0" -I"%GINC_PATH%\glib-2.0" -I"%GLIB_PATH%\glib-2.0\include" -I"%GINC_PATH%\pango-1.0" -I"%GINC_PATH%\cairo" -I"%GINC_PATH%\gdk-pixbuf-2.0" -I"%GINC_PATH%\atk-1.0" -Dinline= /link /LIBPATH:%GLIB_PATH% gtk-3.lib gdk-3.lib gobject-2.0.lib glib-2.0.lib
This compiles alright, gives me gtk3test.obj. However, the linker returns the following error:
LINK : fatal error LNK1181: cannot open input file 'gtk-3.lib'
What am I doing wrong here? How would it be possible to use cl for linking GTK3 applications?
Thank you all in advance!
Xuttuh

Please check if you have gtk-3.lib in your folder path [%GINC_PATH%]. Even I have this issue using GTK+3.0, the package configuration is not giving the proper library reference.
The gtk library is something like gtk-win32-3.0.lib available inside lib folder %GINC_PATH%\lib in your case.
I still have issues in linking GTK libraries in my visual studio application even after providing the needed library references in Linker.

Related

(C) How to link dlls within CLion

I've been programming C for a while with Visual Studio, but now switched to CLion. My programming and target system is Windows10.
Within Visual Studio, I was able to include the required DLLs like "vcruntime140d.dll" and "ucrtbased.dll" inside my exe.
I did this by going into the project settings and set configuration settings - C/C++ - code generation - runtime library to "Multithreaded-Debug (/MTd)".
Doing this I was able to run the resulting exe without having errors like "vcruntime140d.dll is missing" or "ucrtbased.dll is missing".
But how can I achieve this within CLion?
I've been searching for a while now, and I found a lot of tutorials on how to include .lib files but not for DLLs (I don't have the code for).
With Clion, you actually are working with CMake. So the question is to be like how to link dlls within CMake.
There are many ways to do. e.g.
link_libraries
target_link_libraries
If the library could not be found by default, use find_library to search for it.
If these functions seems too strange to you, check this tutorial from the CLion team.
Update
As in the comment you asked, your problem is how to load a dll without lib. To address this, you could dynamicly load the dll, or make a lib from the dll.
For Windows multicopies problem, add following into your CMakeLists.txt
foreach (flag_var
CMAKE_C_LINK_FLAGS
CMAKE_C_LINK_FLAGS_DEBUG
CMAKE_C_LINK_FLAGS_RELEASE
CMAKE_CXX_LINK_FLAGS
CMAKE_CXX_LINK_FLAGS_DEBUG
CMAKE_CXX_LINK_FLAGS_RELEASE
CMAKE_EXE_LINKER_FLAGS
CMAKE_EXE_LINKER_FLAGS_DEBUG
CMAKE_EXE_LINKER_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELWITHDEBINFO)
string(REPLACE "/MD" "-MT" ${flag_var} "${${flag_var}}")
endforeach ()

How to use VC++ compiler in command line(Windows)?

I tried to use VC++ commandline, instead of MinGW compiler for windows system programming. I wrote a simple hello world program and tried to compile it, then i got this error message.
test2.c(1): fatal error C1083:'stdio.h': No such file or directory
I also added "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\Hostx86\x86" directory (where c1.dll lives) to the System Envionment Variable(PATH).
How can I fix this issue? Other tutorials don't give much information about VC++. (A lot of MinGW compiler tutorial out there btw)
You should use visual studio command line if you want to compile or run program with the help of vc++ compiler.
Else all information related to setting environment variables ETC. resides in this MSDN document.

GTK Linker Issue Visual Studio C Project

it is the third day that I am trying to set up the visual studio 2013 with the GTK libraries. I need to use VS: I've used GCC (both command line and with code blocks) in the past (both on windows and slackware linux too..), but now I have a lot of projects in VS and I want to start making some GUI for them. After seeing that the so called "all-in-one-bundle" is not more available/maintained in the GTK website, I followed a bunch of tutorials (including GTK+ 3.0 setup in Visual Studio 2013, How to configure gtk on Visual studio 2010, How do you install GTK+ 3.0 on Windows?) and I started to install MSYS2 according to this one: https://blogs.gnome.org/nacho/2014/08/01/how-to-build-your-gtk-application-on-windows/.
Maybe the problem is here: I followed this step properly pacman -S mingw-w64-x86_64-toolchain, but I skipped the creation of PKGBUILD file and successive installation due to the fact that I did not understand the procedure. Furthermore the mingw toolchaing seemed to be already installed.
Sorry for the big introduction, I wanted to be specific.
The problem is at the linking-stage of Visual Studio C Project building. I had also some problem at compilation involving the different inline interpretation of VS (added #define inline __inline // Necessary to make the GTK library Visual Studio compatible definition before calling the GTK header). The linking stage issue consist in the fact that, using pkg-config --libs gtk+-3.0 --msvc-syntax command, I receive a list of files (/libpath:C:/msys64/mingw64/lib gtk-3.lib gdk-3.lib gdi32.lib imm32.lib shell32.lib ole32.lib -Wl,-luuid winmm.lib dwmapi.lib z.lib pangowin32-1.0.lib pangocairo-1.0.lib pango-1.0.lib atk-1.0.lib cairo-gobject.lib cairo.lib gdk_pixbuf-2.0.lib gio-2.0.lib gobject-2.0.lib glib-2.0.lib intl.lib) that does not exists in the msys2 directory. As a consequence I receive this error from the linker: error LNK1104: cannot open file 'gtk-3.lib'.
Someone has the same problem (see Error 3 error LNK1104: cannot open file 'gtk-3.lib'), but the solution is to use the all-in-one-bundle.
What shall I do? Have I followed the correct procedure or am I missing something? I've also tried to link to VS the *.a files located in the lib directory of mingw63 (e.g. libgtk-3.dll.a), but the linker error remains.
Best Regards and thank you for the attention
Davide

Cannot include certain header files using the Visual C++ compiler

Hello I'm getting into Winsock programming in C. I believe that in order for me to access the (or any other header related to Winsock for that matter) header file I have to have Visual C++ 2010 installed and set it as my default compiler. So I download it, and in CodeBlocks I set it to my compiler. I run some Winsock code and I get this message:
C:\Users\Jared\Documents\Test.c|6|fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory|
I also get this message for including 'winsock.h' and 'windows.h'. This has something to do with the Visual C++ compiler. I try installing Visual C++ 2008 and use it as my compiler and get the same message. I then read that I have to install microsoft's SDK. I download and install it and it gets an error saying that I can't install it (this is the .Net framework 4.0 version). I then try the 3.5 version and it installs fine but my compiler still can't find the header files. I have the .net framework 4.0 so I don't see the problem. I also read that I have to include some header files in Visual C++ by going to Tools>Options>Projects and Solutions>VC++ Directories and I get the following message:
"VC++ Directory editing in tools > options has been deprecated."
Visual C++ 2010 no longer supports this feature. Does anyone have a solution or can help me with this?
Long story short: I cannot include 'winsock.h', 'winsock2.h', or 'windows.h' using the Visual C++ 2010 compiler.
All help is appreciated.
In Visual C++ 2010 it is recommended to use property sheets instead of this kind of global directory settings editing. You need to edit the user settings property sheet (probably Microsoft.Cpp.Win32.user.props) in your AppData folder. You can do it in the UI through the Property Manager via View->Property Manager and browsing for that sheet.
However, I think you should have $(WindowsSdkDir)include in Include Directories if you have it installed correctly.

How to configure visual studio 2010 with opencv cvblobs library

I'm having difficulty of installation/ compilation of cvBlob into OpenCV Microsoft Visual Studio 2010 in WINDOW. I understood that there is a installation guide work on linux but I couldn't find how it can be done in Window.
I would appreciate if someone may provide me the installation guide in WINDOW as I found that cvBlob is very useful for my project.Thanks
For the moment there is no pre-built cvBlob for Visual Studio, so you are going to have to compile it yourself.
So before you start, make sure you have OpenCV installed in your computer.
Download CMake for Windows. CMake creates the Visual Studio project files that are needed to compile cvBlob.
Once you open cmake-gui, fill in the edit boxes "Where is the source code" and "Where to build the binaries" accordingly (adjust these to your settings):
C:/Documents and Settings/user/Meus documentos/Downloads/cvblob-0.10.3-src/cvblob
C:/Documents and Settings/user/Meus documentos/Downloads/cvblob-0.10.3-src/cvblob/build
Note: the build folder was created manually.
Click on button Configure to check for dependencies (CMake will try to find OpenCV on your computer) and then on Generate so it can generate the Visual Studio project files.
From here on it's the standard compilation procedures.
karlphillip's answer is correct, and you should follow it. Be advised, however, that if you're building the files using VS 2010, a few of them will fail and return this error:
LINK : fatal error LNK1104: cannot open file '..\lib\Debug\cvblob.lib'
To get around this, add the following to your cvblob.h file:
#define EXPORT __declspec (dllexport)
In the extern "C" block below that, add EXPORT before every function. For example:
EXPORT double cvContourPolygonArea(CvContourPolygon const *p);
After running into this error myself, I found the explanation here (which I adapted to make this post; all credit belongs to this link's author): https://code.google.com/p/cvblob/issues/detail?id=34
Just something you might want to watch out for. Hope it helps!

Resources