Using static libraries on a C project in XCode 4.5.2 - c

I'm new to Xcode so not really keen on it yet. In my college is used visual studio to program in C in which they create a solution and fill it with an application and then include static libraries with .h and .c files. Been trying to do this in Xcode but can't seem to include them or add dependencies like in Visual Studio

One approach is just using the standard gcc command line options for static library linking which you can specify using the XCode project settings. This will work if the static library is installed and accessible in the standard locations.
Alternatively you can add a static library explicitly to your project and set the dependencies and search paths for headers etc appropriately. This may sound a bit involved, but there's not really that much to do, and you only need to set it up once. It's all done in the same place as other project settings, and you can use the search box to find exactly where to enter the options.
I'm assuming you don't want to actually build the static library with your project. if you do there's more to do - basically you need to set up the static library project, set it as a target dependency, and setup a build step to copy the resulting library.

Related

How would I link a `.lib` library from a different solution in Visual Studio 2019?

Currently I am building a static library to read bitmap images in C. I am wanting for others to be able to link the library without access to the Visual Studio project it was created in. I can not figure out how to link my '.lib' file to another project, any ideas?
I am trying to use Visual Studio 2019. My '.lib' compiles successfully, when I reference it in another project (by adding a reference in the solution explorer) within the same solution everything works as intended.
However when I try to add it in a different solution by either setting the additional dependencies and library directories in the project configuration or adding the library to the resources folder the linker can not find the definitions for my header files in the library.
I have tried to set
Properties>Linker>General>Additional Library Directories
and
Properties>Linker>Input>Additional Dependencies
Both the properties I type in evaluate to the correct path but i still have no luck.
I expect my program to compile and run as it does when adding a reference to the library project within the same solution.
What i receive is:
Error LNK2001 unresolved external symbol (any function symbol here)
Any help is appreciated, this is my first question so I am sorry if it is unclear :).
You can link libraries through the #pragma directive. Try this.
#pragma comment(lib,"libname") At the top of your C/header file. Where libname is obviously the name of your library you are linking. The quotations need to stay.

How to use modbus library in a Visual Studio 2017 project?

Full disclosure: I'm not a C/C++ programmer, I can write basic programs like a calculator or some other very basic stuff where you don't need to use external libraries.
My goal is to use this modbus C library in a proof of concept piece of code that runs just the example line (with the IP and port changed) however I cannot wrap around my head on how to use the library.
In Python I know I could just run
import library_x
and I'd use Python, however the code needs to be in C and am completely lost when it comes to add this library. My understanding is that I should compile it in a static or dynamic library (dll) but I don't know if it's the right way to go.
Basically:
I want to run the example code in the documentation in the main of a C program, how can I do it?C
I am using Windows 10 and Visual Studio 2017.
I tried to add all the header files in the library (.h) in the Visual Studio project and compile it but it did not work.
This question has been already answered here:
libmodbus in MFC
I don't use Visual Studio but even if you don't want to use the project templates it should be quite straight forward to compile the sample code whatever your tools and environment: you have to point your compiler to include the headers and link using libmodbus. On Linux, after installing the library of compiling from sources you just have to:
$ gcc -o your_modbus_example -I/usr/include/modbus your_modbus_example.c -lmodbus
The unit_test_client.c and unit_test_server.c files provided with libmodbus should compile and work out of the box.

Making exe-file in c portable - static linking [duplicate]

I have installed GCC and GTK+. Its working fine, but i need to statically link GTK+ libraries with my application (it's a small application) so that there exist only one '.exe'.
mingw-cross-env has fixes to build gtk and all related libs statically
It is supported with a few minor issues (like having trouble finding configuration files), but you will have to compile GTK+ yourself! (the default binaries do not include static libraries)
See this mailing-list thread for more information on this issue.
The correct answer would be two words: not supported. Really, if you want to distribute your application, being it 2 or 100000 lines, just bind a copy of GTK+ with it.

Are there any GUI toolkits that exist as a C DLL?

Are there any pre-built GUI toolkits that exist as a C DLL?
So i can simply import a static library and start using GUI commands to build an application written in C? Also so i can redistribute the dll with my application.
EDIT: Preferably with no dependencies or that they too are dlls.
IUP comes in pre-built packages. Scroll down to read which version you should get depending on which dependencies you want or which compiler you're using.
Note that your preference to have no dependencies is almost impossible considering that most toolkits will link against some msvcr***.dll, IDE-specific libs, or other lower-level open-source libs.
Realistically though, you should probably just pick your favourite toolkit and then compile it yourself along with all the dependencies, put them all into a folder, and that folder is what you link against to use the toolkit. Once you do that initial compilation it'll be just as easy to use as a precompiled one. Another advantage of compiling it yourself is you can pick which extras or extensions you wish to bundle in and which you won't need, which optimises the output filesize.
You mean like GTK+?

Adding GraphicsMagick to an Xcode project

I have created a Foundation Tool in Xcode, and want to use some functions from the GraphicsMagick image manipulation library. The library has been compiled and installed on my computer using MacPorts. I added libGraphicsMagick.3.dylib and libGraphicsMagickWand.2.dylib to my project as external frameworks.
What other steps must I take to use these libraries in my application, and how would I import their headers to use their functions in my code?
Thanks
UPDATE: Made some progress. Used the .a static libraries instead of the dylibs, added them to my project, then added the header files for magick and wand. I'm trying to compile, but I get this error:
alt text http://cl.ly/f4233cddbae23e1a19fc/content
Searched around a bit, and apparently this problem occurs because 2 of the typedef enum declarations that GraphicsMagick and ImageMagick use are already defined in OS X framework headers. The enums in question are ColorInfo and ExceptionInfo.
The only way to fix it is to go through the source and rename every occurance of those enums to a new name that isn't already taken. However, the iPhone does not have this issue and GraphicsMagick will compile just fine. Unfortunately, I don't think the people behind the library are willing to rename their enums just to get it to compile on OS X.

Resources