Linking Code::Blocks custom libraries error (cannot find) - c

I'm struggling with the Code::Blocks IDE when programming in C.
I use one custom library, named "main.h".
Yesterday, when I begun working on the library, the program compiled without errors. I even put some functions written on the library on my source file and it built and ran fine.
Today, when trying to recompile the whole project after some modifications, appeared the "undefined reference" error.
I searched it over on this site, I tried to follow the steps another user proposed but now, instead of the "undefined reference" error, appears the "cannot find -l[filename]".
I tried to collect information about this error on this site as well but, I understand, it's a OS problem and, apparently, never happened to other Code::Blocks users.
I use Windows 7 64 bit, in case this is the problem.
Can you please help me?

Try to put fullpath to library in build options of your project and be sure to put it in the right build scheme(Debug/Release) or both to be sure.
However it is quite strange name for library - "main.h". Is it "main.h.dll" or what? Maybe it is header file? If it is so and you put implementation of you functions in .h file and not in .c, some errors could occur.

Related

LNK2005 and LNK1169 when trying to compile program in Visual Studio 2019

I have no experience with C/C++. I do not know how to even open files. I am working with SLN files in Visual Studio 2019 trying to compile a program I took off of GitHub (https://github.com/Marlowe97/Expected-Force).
I get these two errors (LNK2005, 'main already defined in TestExpectedForce.obj, and LNK1169 'one or more multiply defined symbols found') when trying to compile the Expected Force solution. The only changes I've made from the downloaded files are the ones directly stated in the instructions on the GitHub page of the program.
Is there someone who can tell me what to look for in as plain of a way as possible? I know basic Python and R so I understand some terms, but I know nothing about C so no other posted solutions to these errors make any sense to me. I'm already pretty concerned that I'm getting errors after following the step by step instructions from GitHub on what seemed to be a pretty basic task.
It's a strange package...
The functionality is provided as a library, to be compiled into your own project.
There are TWO test source files: TestExpectedForce.cpp and TestExpectedForce.cpp, each of them contains main().
They should be in their own projects (possibly, under the same solution).
To quickly move forward, just remove one of the test files from your solution.

Trying to understand simple task of adding files to VS projects

As I said before, I'm still learning. Per the comments in this previous post, I'm trying to add a file into an existing project, rather than including it. The source code is listed in the previous post. I used these instructions to add the file to the project. I renamed the include file from FilMst5.c to FilMst5.cpp to avoid the following error:
C1853 'x64\Debug\CrtFil5.pch' precompiled header file is from a previous version of the compiler, or the precompiled header is C++ and you are using it from C (or vice versa)
I also added #include "stdafx.h" to prevent another compile error message. When I tried to compile the project files, I got 2 messages 'FilMstFilPtr': undeclared identifier and another message 'Opn': identifier not found. So I know I'm doing something wrong, but I don't really understand how it's supposed to work in order to fix it. Can someone tell me the correct way to do this?
The C code previously compiled fine even though it has a .cpp extension, the way Visual Studio does things.
I apologize for anyone wasting time on this question. I just needed the necessary declarations in a header file, and the linker took care of the rest of it.

Trying to solve WindowError 126 - module not found

Though this is my first question on the StackOverflow, I consider myself a long time member of the community.
Considering myself as a pre-intermediate programmer, I'll try to be as specific as possible.
I'm writing a Python package that uses a C dll to load image files with ctypes. I'm using Python 3.3.5 32bits version on Windows 8 x64. I had to build the dll from the C code. The dll is stb_image.h which is available in GitHub. I used Code::Blocks version 13.12 with the GCC compiler. The dll seems to have built fine.
By my definition, the dll is must be in the same folder as the py code file that wraps its functions, but when ctypes attempts to load the dll an exception is raised: the [in]famous WindowsError: [Error 126] Module not found.
I've found several similar questions and attempted to glean from their solutions by
adding the dll path via os.environ['PATH']
adding the dll path manually in the Path environment variable
changing the current working directory with os.chdir()
using the file module attribute to locate the library
none of these solved the issue
The stb_image library itself has no dependencies so I don't understand why windows can't find it since the dll is where it should be and the path addresses it's exact location. And, of course, there's a lot of other ways to get the job done: PyGame, pySFML (which also uses stb_image), PIL, PyPng, PySDL, you name it, but I'm doing this mostly for learning purposes.
At the writing of this question, something popped up in my head (which may or may not have any relation with the problem): whenever I compile and link programs with GCC and try to run them, I got a message box telling me that some dll (libgcc.dll or something like that) was not found. Could that be the reason Windows can't load stb_image.dll?
I tried everything my experience allowed me to do to solve it but it was not enough. Would you guys, please, give me a light on this?
PS.: Sorry for any bad english. I'm natural from Brazil.

Eclipse CDT can resolve macros and functions, but not structures or enums (Code browsing only)

I'm working on a large C project (multiple makefiles, modified third party code, etc.) and I would like to use Eclipse as a graphical front-end for GDB and for browsing/editing the code.
Right now I have a problem where Eclipse can resolve the macros and functions in the code, but not data structures or enums. Please note I am only concerned with browsing/editing the code. I will compile the project outside of Eclipse. I should also mention that Eclipse has no trouble resolving anything from a standard C library. I see that is a common question, but that is not a problem here.
So far I've done the following:
The entire code base is loaded into Eclipse.
I can launch the final application from Eclipse and interact with it in the Console.
The Indexer is enabled and it's set to index source files not included in the build, unused headers, and to not skip anything. I've run the Indexer a few times. I've also tried closing/reopening the project and restarting Eclipse.
I added the directory containing the header files for the project to Properties->Paths and Symbols->Includes. I see this directory under "Includes" in the Project Explorer".
If I'm browsing a source file, I can right click and select "Open Declaration" to see macro definitions and function definitions, even if those definitions are in other files. This is not working for data structures or enums. Eclipse reports Type "StructureX" could not be resolved?
What do I need to do so Eclipse can resolve data structures?
Update
I just looked at the parser.log file. I see "Attempt to use symbol failed:" for the structures and enum members Eclipse can't resolve, but I don't see the reason why.
I found the answer, oddly enough, because the default color scheme was bothering me. When I switched to a more soothing black background, I noticed that Eclipse thought all of the #ifdef DEFINE_NAME_X macros were undefined.
The enums and macros that the Indexer was not able to find were inside these statements.
Once I opened Properties->C/C++ General->Paths and Symbols->Symbols and defined a few key macros, the indexer was able to find the missing symbols.

unknown type name ‘gpgme_decrypt_result_t’ when trying to compile balsa

I've been trying to compile balsa the email reader on ubuntu (i'm new to the whole process of compiling an open source project directly from sources.
so i did the whole configure and make but then I ran into this problem:
error: unknown type name 'gpgme_decrypt_result_t
after doing a little research on the error code.. it turns out that it belongs to gpgme a scary looking encryption library..
what do I do in this case? i hope i'm not expected to go in the code and debug stuff am i?
update:
this question is related to this other question here on the ubuntu forum
Unfortunately, you may be required to delve into the code to figure out why something doesn't build!
In this case however the answer is probably quite simple. The main reasons I would expect a symbol from an external library to not have been defined are:
The library header files do not exist on your system
You have the wrong version of the library header files on your system
The headers exist, but the compiler is not looking in the correct place
Clearly the solutions are similar: you will need to install the correct version of gpgme's header files for this software in the right place. Note that having the library itself installed is not the same as having the headers. In Ubuntu this is evident due to the presence of -dev packages which are the package's header files, and if you look through the repose you will find libgpgme11-dev. I suggest you start by installing this, which will eliminate point 1 above. If it still doesn't work, you'll need to start investigating the other two possibilities.

Resources