Import files exists to project eclipse C++ Linux - c++

I am using eclipse to dev my application for linux. I have my library source in workspace/mylib/ and the project in workspace/project.
In a source of my project i include the relative path of source library file,
example: #include "../mylib/foo.h"
The problem start when i try build it, in all parts that use library source eclipse shows this error: undefined reference to 'function()'
I think that it is by library files don't have in src folder or not link.
Any Idea?
Thanks!

error: undefined reference to 'function()'
Indicates that the linker cannot find the definition of the function(). Either you have not defined it in your source code Or If you are using a library which defines it, the library is not getting linked.
This or this posts explain what you should do to add external libraries to eclipse.

Related

Problems Building C++ Static Library for XCode iOS

I have a large iOS project in Objective-c that also has a large number of C++ classes in a 6 subfolders. If I have all of the C++ source code in the iOS project and compile from the source files, everything compiles and works just fine. All good so far.
I wanted to move all of this C++ code to a static library, so I created a new project and a wrapper for my classes and compiled it as a Static Library based on the numerous sets of instructions on SO. It compiles without any errors and created the .a output file with the appropriate header.
When I include this Static Library into my project I get 11 errors related to:
Undefined symbols for architecture arm64:
"Configuration::Configuration()", referenced from:
___cxx_global_var_init in libMInterfaceLib.a(M-
3fdac31d875d4f01157909522738d4c95b3c465d55314d375878e8f2faec0803.o)
"Type::GetSizes(int, int, int&, int&, int&)", referenced from:
CM::BitSizes() in libMInterfaceLib.a(M-
3fdac31d875d4f01157909522738d4c95b3c465d55314d375878e8f2faec0803.o)
When I use the lipo info command I get confirmation that my Static Library is architecture: arm64
$lipo -info libMInterfaceLib.a
Non-fat file: libMInterfaceLib.a is architecture: arm64
Which makes sense because I'm building the Static Library for a device and including it in a device build. I'm not using a Simulator for this project because it needs a live camera so I only need one Architecture which is arm64.
If I create a Static Library from the same code for the Linux version of the application it works just fine, so I know the basic code, headers and file structure is good. That Static Library says it is architecture x86_64 according to lipo -info which make sense.
$lipo -info libMInterfaceLib-OSx.a
Non-fat file: libMInterfaceLib-OSx.a is architecture: x86_64
The other thing I see is that the .a file built by XCode as a Static Library is 732KB, but the file built by eclipse for Linux from exactly the same source files is 2.2MB. Why would they be so different? All of the source code that is supposed to be included is 1.6MB.
I get the feeling that the problem is not that the Static Library is the wrong Architecture, but that it is not including all of the C++ files that are in the subfolders of the project. The other issue I see is that if I misconfigure the Static Library XCode Project to compile as an executable, I get exactly the same set of errors as I get when I include the Static Library into the device project, but I don't quite know what to make of that other than its not compiling all of the files. Its also super fast to compile which leads me to believe again that its not building everything into the Static Library that it should. Remember, when this C++ source code is added and compiled as part of the main project it all works fine.
Does anyone know how to ensure that XCode will include all of the files in the subfolder and classes that are associated with them? Is there a special linker setting that I need to be using in XCode to get it to link all of the C++ files that are part of the Static Library project?
Anyone know where I'm going wrong here?
Any help and guidance is greatly appreciated.
OK, So after a bunch of messing around I realized that just including the folders into the Static Library project didnt work. I had to create individual Groups for each folder and then import all of the files into those Groups as files in the folders. As there were multiple levels of files this was a pain in the arse but the final blurry eyed late night clue was that the folders in XCode were Blue and not Yellow. That was the only indication that they werent all included. There we no compilation errors in the Static Library project, it was only when trying to use that Static Library in another project that any errors showed up. I've been caught by the same thing before and should have recognized that when folders are Blue in XCode, it hasnt imported your files even though they show up inside and appear to build. C++ Static Libraries in XCode do work and its simple once you have all the files included in the Static Library project.

errors at building a cpp code using visual studio [duplicate]

I'm using the <XZY> IDE to compile my program, and have some trouble to import/integrate a specific library with it.
I get error messages like
fatal error: 3rdPartyLib.h: No such file or directory
for a
#include "3rdPartyLib.h"
statement
ld.exe: cannot find `lib3rdParty.a`
for specifying
3rdParty
in the additional libraries
At least I got some error message like
undefined reference to `lib3rdParty::foo()'
What can I do to fix this?
It's a common misconception, that the current IDE used, is responsible for getting errors like stated in the question.
See for example
c++ lib in two same project ,one can work but the other can 't
Issue linking libxml++ and glib libraries with CodeBlocks IDE for C++ Windows
...
The problem is almost never related to the currently used IDE.
In the most cases the solution boils down, to supply the actual toolchain's compiler/linker with the appropriate path's to search for included headers, to be linked libraries.
One of the major applicable answers for the linker related problems are
What is an undefined reference/unresolved external symbol error and how do I fix it?
undefined reference to `WinMain#16'
Most of the common IDEs provide features to configure this for a specific project. Here are some samples
Eclipse-CDT
Include path settings:
Library & library search path settings
Visual Studio 2013
Code Blocks
**DEV C++ (Bloodshed C++)
As from their FAQ:
9. How can i use the OpenGL library and others ?
All the libraries that comes with Mingw reside in the Lib directory. They are all named in the following way: lib*.a
To link a library with your project, just add in Project options, Further option files :
-lopengl32
This is for including the libopengl32.a library. To add any other library, just follow the same syntax:
Type -l (L in lowercase) plus the base name of the library (filename without lib and the .a extension).
You may also consider putting a -L option there to add directory pathes searched for libraries.
Qt Creator
In order to add include paths you have to open up the .pro file and then add
the directories to the INCLUDEPATH variable. These paths are separated by spaces. Reference can be found here.
If none of the above samples applies for your actually used IDE/toolchain, I hope you're able to get the point of abstraction:
It's an issue how to provide compiling/linking options to your actual toolchain. The IDE used to setup the context is a minor point here.
For eclipse I use the pkg-config plugin where possible:
https://marketplace.eclipse.org/content/pkg-config-support-eclipse-cdt
Failing that this configuration window:

Netbeans C++ using MinGW and the libnoise library

Using netbeans 7.2 and the most recent version of MinGW (using installer) I can't use the libnoise library. I am properly including the header files, the auto completion confirms this, however the library is simply not working. There is a .lib file and a .dll. I have tried every possible combination of adding them under project > properties > Build > Linker as well as putting the .dll in the base project directory. Despite all this I am still getting undefined reference errors whenever I try and run the code. Does anyone know what to do?
I know that it is possible to link import library files (*.lib) with MinGW, but I still suggest to recompile libnoise.
With the current Makefile, this is not very easy and may break. Thus I've written a CMake script, which doesn't only work on Windows, but should work on all CMake supported platforms. In addition to this, I've cleaned up the directory structure. The code itself hasn't been touched and when you build a library it should essentially be the same as the current one.
libnoise on GitHub
After you've built your shared library, you'll have a libnoise.dll.a and libnoise.dll file. You then add libnoise.dll.a to the linking settings and put the DLL itself next to the binary, or in the working directory.
You have to link the lib file (= adding it to linker libraries) and put the dll to
<project root>/dist/<...>/
(where your exe is put to). There's no need to add the dll to linker too.
Can you please post the error message you get?

How to use my library in C++?

In Eclipse I have created two libraries. One of them is shared another one is static. I have compiled them in Eclipse and as a result a Debug folder was created (for both libraries) and these folders contain make-files as well as object files (*.o) and dependency reference file (*.d). In addition to that, the static library contains an *.a file.
Now I create a new project and what to use these library in this project. Normally, when I use a library I type #include <libraryname>. But if I use #include <mylibraryname> it does not work (I get unresolved inclusion). And this is not surprising because Eclipse should somehow know where my library is located. So, my question is how can I inform Eclipse about the locations of my libraries.
ADDED As recommended I do the following sequence "Project -> Properties -> C/C++ Build -> Settings -> Tool Settings -> GCC C++ Linker -> Libraries". Then, in the "libraries(-l)" filed I add "StaticList" (because I have "libStaticList.a" file) and in the "Library search path (-L)" filed I give the full name of the directory where my "libStaticList.a" is located. Then I click Apply and OK. But it does not help. Eclipse does not like #include <StaticList>. It complains: "Unresolved Inclusion..".
#includeing headers only makes the compiler aware that the functions in those headers exist. The actual implementation of those functions needs to be linked in by the linker. That's where the library (.a) files that you built come in. Check out this thread for an example on how to link in your libraries using Eclipse.
I think you need to #include "yourlibrary.cpp" (between double quotes) instead of < >.

C++ linker options for DLL (DEF, LIB, etc)

I have downloaded a library for the purposes of writing a program that can uncompress a RAR file. (http://www.rarlab.com/rar/UnRARDLL.exe) This supplies me with unrar.dll, unrar.h, unrar.lib and UnRDLL.def. I have copied the C example code and have tried compiling it with both Dev-Cpp and Eclipse.
I don't have much experience using DLLs, so I don't know how to deal with the following linker errors:
UnRDLL.o(.text+0x151):UnRDLL.c: undefined reference to RAROpenArchiveEx#4'
UnRDLL.o(.text+0x1c0):UnRDLL.c: undefined reference toRARSetCallback#12'
UnRDLL.o(.text+0x1e2):UnRDLL.c: undefined reference to RARReadHeader#8'
UnRDLL.o(.text+0x2b9):UnRDLL.c: undefined reference toRARProcessFile#16'
UnRDLL.o(.text+0x2fe):UnRDLL.c: undefined reference to RARCloseArchive#4'
UnRDLL.o(.text+0x366):UnRDLL.c: undefined reference toRAROpenArchiveEx#4'
UnRDLL.o(.text+0x3d6):UnRDLL.c: undefined reference to RARSetCallback#12'
UnRDLL.o(.text+0x41c):UnRDLL.c: undefined reference toRARReadHeaderEx#8'
UnRDLL.o(.text+0x4c2):UnRDLL.c: undefined reference to RARProcessFile#16'
UnRDLL.o(.text+0x4fa):UnRDLL.c: undefined reference toRARCloseArchive#4'
Google suggested adding --def UnRDLL.def and -lunrar to the linker options and also copying the .lib file to the Dev-Cpp\lib directory.
Can you please explain to me what I'm doing wrong? If possible, tell me what files need to be in the source code directory, what needs to be with libraries, what needs to be added to the project and what linker options there need to be, as well as anything else I've totally missed.
EDIT: I don't know why, but I just manually redid all the settings as described above and now it works. Thanks for your help anyway.
I recommend using Visual Studio Express (freely available from Microsoft at the provided link) to compile and link your program. I think it's a bit simpler in this instance than the other tools that you mentioned, although that's just my personal opinion.
I recommend using a layout similar to this for your project:
\myproject
\src
\include
\thirdparty
\bin
\lib
\include
Your C/C++ source files will live under myproject\src and your header files will live under myproject\include. The library files that you downloaded live under thirdparty: the DLL belongs in bin, the .lib file and .def file belong in lib, and the library's header files belong in include.
Next, you need to configure your project in Visual Studio Express. In your project properties, under Linker -> General, add \thirdparty\lib to Additional Library Directories. Under Linker -> Input, add unrar.lib to Additional Dependencies. This tells Visual Studio Express the name and location of your thirdparty library, so that it can link it into your main application.
When running your program, you'll need to copy unrar.dll to your project's output directory so your program can load it.
This should help you to get going...
Back in the day, Borland used to supply a tool for creating a lib file from a def file.
In the modern world, your best bet is to add the lib file to your project under Project->Properties Config Props->Linker->Input->Additional Dependancies.
You may need to add the lib file location to Props->Linker->General->Additional Lib Dirs.
Make sure the DLL is on your path or copied in with the executables.