Netbeans - How to add external C libraries? IUP - c

I'm learning C, and I want to use my first external library.
Firstly I'll show the simplistic code I'm trying to compile:
#include <stdlib.h>
#include <iup.h>
int main(int argc, char **argv)
{
IupOpen(&argc, &argv);
IupMessage("Hello World 1", "Hello world from IUP.");
IupClose();
return EXIT_SUCCESS;
}
The external library being IUP.
I have downloaded the following to my documents folder:
Then I configured Netbeans build options by first adding the header file directory:
Then finally I added the .dll file:
https://prnt.sc/slf1z8
(I added a link because I thought the post was getting too long)
However, while the code no longer shows a red underline under the functions I'm trying to use, the compiler shows "cannot find -liup"
I don't know what could be going wrong. I was following this link tutorial:
http://webserver2.tecgraf.puc-rio.br/iup/en/ide_guide/netbeans.html
Thank you!

When you link, even using a DLL, you need a ".lib" or ".a" file depending on the compiler. In this case this library is called an import library, and contains just "pointers" to the functions in the DLL.
The IUP packages include those import libraries you need. Probably you downloaded package iup-3.29_Win64_dllw6_lib.zip which include the ".a" files you will need.

Related

How to include libssh to my project

I've installed libssh following the instructions and even though everything seems to be OK my compiler still returns the error "file not found" in the line "#include ". I guess it has something to do with directories or links (I have "make install" in the same folder where I downloaded it) but I don't know where should I put it so I can #include it in any project.
This is how I installed it:
I downloaded it and unzip it into the folder "libssh" on my Desktop (Mac).
Then I did
cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug ..
make
and finally:
sudo make install
Then in my program I have:
#include <libssh/sftp.h>
And XCode returns: "libssh/sftp.h file not found". I tried adding the libssh folder in the Desktop to the project, but I still have similar problems.
I guess I should install it (somehow) to the /usr/include folder, so that any project can use it (like pthread or many others), but I don't know how to do this.
If I include any other file in /usr/include it works fine (like ) but when I #include it returns file not found, even though if I cd to /usr/include/libssh the file libssh.h does exist.
This is the very simple sample code:
#include <stdio.h>
#include <pthread.h> //OK
#include <libssh/libssh.h> //Not OK, file not found.
int main(int argc, const char * argv[])
{
printf("Hello World!");
return 0;
}
In the tutorial is described how you have to link the library
You have two possibilities here:
As described you have to add those two lines to your code
#define LIBSSH_STATIC 1
#include <libssh/libssh.h>
You compile your code with the LIBSSH_STATIC flag.
gcc -DLIBSSH_STATIC test.c -o test.o
I thought that if you have the library in /usr/include the compiler will automatically link it. For instance, the pthread.h file is included properly without doing anything.
This is a system library which gets linked automatically most of the time. libssh is not. Thats why you have to be more specific on how to compile/link it.
Ive had a very similar problem several times and I have solved it by removing the ≤ ≥ symbols from around my header files and using ""s and the absolute path to the header file you're including. Now this doesn't solve your libssh install problems but it will allow you to compile just the way you have it as long as you know the absolute path of your header file and all of your header's dependencies are in the respective locations that they were inteded to look for them in. Hope this helps.

Open new C project with eclipse for new developer

I want to start learning C and download Eclipse for C\C++ and want to start new project.
I found this tutorial and after create new project, choose C project with MinGcc and hit finish this is the errors i got:
Symbol 'EXIT_SUCCESS' could not be resolved
What i am doing wrong ?
EXIT_SUCCESS is defined in stdlib.h:
#include <stdlib.h>
int main(void)
{
return EXIT_SUCCESS;
}
Based on your comments, your problem appears to be with Eclipse. You might want to try off the main menu:
Project->C/C++ Index->
Freshen All Files
Update with Modified Files
Re-resolve Unresolved Includes
Search for Unresolved Includes
In the Project Exlorer tree, it lists where Eclipse CDT looks for include files. You should see a directory in there that holds stdlib.h. On my machine it is in c:\MinGW\include.

Linking to a DLL I created

I am trying to create my own DLL and then make another project load it statically.
My DLL file contains both a header file (called HelloFunc.h):
#include <stdio.h>
extern "C"
{
_declspec(dllexport) void HelloFromDll();
}
And a c file (called HelloFunc.cpp):
#include <stdio.h>
extern "C"
{
_declspec(dllexport) void HelloFromDll()
{
printf("Hello DLL. \n");
}
}
After building the project an Object File Library (.lib) was created.
Then, on my other project I tried to link to it statically.
In linker -> Input -> Additional Dependencies I added my library (I put it in my new project's directory) and then in linker -> Input -> Command Line I saw that it actually linked to it.
However, when I tried to call HelloFromDll() function in my new code, an error says that it is not identified. Note that I also included "HelloFunc.h" but an error says that the source file couldn't be opened.
I'm a little lost and don't know what I've done wrong. Any help will be appreciated :)
You must specify __declspec(dllimport) instead of __declspec(dllexport) when importing a library.
What error message did you received exactly?
[Edited]
When you compile a DLL, you specify __declspec(dllexport). When you compile an application that imports the DLL, you specify __declspec(dllimport).
The problem is that the compiler cannot find HelloFunc.h: Simply copy HelloFunc.h into your new project's directory.
Check that you client & library were compiled in the same mode (debug or release).
This is common bottleneck.

Create and link a .dylib in Xcode in C

I'm stuck with a problem.
Well, I want to create my own dylib file, and inside of it write some methods, etc. You know, just a normal library.
Ok, so I opened Xcode, New project, and I selected Dynamic library. I've created a *main_lib.c* file, and wrote this method inside of it:
void printMessage(char *str){
printf("%s", str);
}
Obviously, I linked this file with the .dylib file and builded the project, no errors. After this, I created another project, selected Command Line Application and created a main.c file.
I imported the builded .dylib file in this project.
I asked one friend of mine, he said that at this point I should create an header file and write inside of it the function prototype of the dylib. So I created a main_lib.h file and declared this prototype:
void printMessage(char *str);
At this point, I write in the main.c file this code:
#include <stdio.h>
#include "main_lib.h"
int main(void){
printMessage("just a try");
return 0;
}
But when I build this it says:
ld: symbol(s) not found for architecture x86_64
It means that the compiler cannot find printMessage, right? But why? What am I doing wrong? Please help :) Thanks in advance guys!
To include it just add it to Target Dependencies and Link With Libraries in "Build Phases" and thats it, it should work.

Including a static library in a C project (Eclipse)

I'm currently developing an application using SDL. In order to utilize it, I have already added the library and header files in the project's settings under C/C++ Build -> Settings -> Tool Settings -> Libraries/Includes. However, when I try to build a test program like
#include <stdio.h>
#include <SDL/SDL.h>
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Quit();
return 0;
}
I get this beautiful error message during the link process:
d:/programme/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../libmingw32.a(main.o): In function main':
C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference toWinMain#16'
Which is rather weird, given that the directory C:\MinGW doesn't even exist at all.
The command used for linking is this one:
gcc "-LD:\Programme\SDL\lib" -o test.exe test.o -lsdl
After two hours of trying to get a library link to work, I'm pretty confused and have no idea what I'm doing wrong. Help would be appreciated.
It looks like you are building a Windows GUI application, which requires a WinMain, while your code only provides a main function which would be for console applications.
So if this is supposed to be a console application, you must adjust your linker settings accordingly, or you must declare a WinMain.

Resources