I tried to add my USART library to my project but I am still failing to properly add it so it will be recognized.
I created an USART.c and USART.h file, which I want to add. This is what I tried:
1) Right Click on the Solution / Properties / Toolchain / Directories
2) Adding the Path where I got these two files
When I try to build the project, it did not work. I get the message undefined reference to 'initUSART'.
How do I add my own libraries to projects then?
The screenshot in your question shows that you arranged for the compiler to find the header files for your library. But you also need to use the compiler to compile your library functions (e.g. initUSART) and create a static library file (with a lib prefix and a .a extension). You would need a separate Atmel Studio project for that, or learn how to use the AVR GCC toolchain outside of the IDE to compile libraries. Then you need to put that file in a directory that is in the linker's search path for libraries, and then you need to pass the appropriate -l argument to the linker. For example, if your library is called libuart.a, you need to pass -luart to the linker. The Project Properties for an Atmel Studio project has the relevant settings you need to configure.
GCC has a standard way to compile, create, and link to static libraries, which I outlined above. You can learn about that from any tutorial on GCC static libraries. You then would need to apply that knowledge to the AVR GCC toolchain, and find the appopriate options inside Atmel Studio that you need to set.
Aside: Atmel Studio does not make it easy to use libraries at all. The Arduino IDE does a much better job because you just put the source files for the library in the right place and it compiles them for you. There are a huge number of Arduino libraries too; you wouldn't have to write your own UART driver if you could use the Arduino platform.
The simple alternative: If you don't know much about compiling and linking to C libraries and configuring your IDE, you would have a much easier time just copying the library files into your project, adding them as source files, and letting Atmel Studio compile them just like any other source file in your project.
Another simple way of adding folders to your project is to copy/paste the folder into your project and then open Atmel Studio.
On the right side (where is by default Solution Explorer) you'll see all your files except the ones that you just added. Now press the Show all files and search for you folder which should appear grayed out. Right click on it and Include in project. That should be all!
This image should help
I got another solution that might help . i found Include Directories in this path for MegaAvr(8bit) :
C:\Program Files (x86)\Atmel\Studio\7.0\packs\atmel\ATmega_DFP\1.6.364\include
Just Puts All your Library in one Folder And Copy All of It in this path , then include it like another library . For example I created a folder named "ali" in that path , then i copied all my libraries in this folder (like alcd.h , usart.h) and then included in my programes with this :
#include <ali/usart.h>
and done ! just remember to backup your folder before Windows Installation (Drive Format) . Also you can find your libraries (.h and .c) in Solution Explorer -> Dependencies after Code Compilation .
GoodLuck ...
inside Folder
including xio.h in folder ali
xio.h in dependencies after compilation
my folder in specified path
Related
How do I add a Static Library to a VS 2015 Fortran Project?
I've searched for the answer to this question online, but the solutions I've found (linked below) don't seem to work for me.
How to link a .LIB in a MS Visual Studio / Intel Fortran project?
https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/393843
I'm using VS 2015 and Intel Fortran 2017.
I have created a static library from my Utilities project and I would like to be able to use the 'Utilities.lib' file in a different project (PhysicsCore) without having all of the source included.
I've tried dragging and dropping the 'Utilities.lib' file into the PhysicsCore Project. I've tried adding existing file and adding 'Utilities.lib'. I've tried adding the lib file and all of the '.mod' and '.obj' files. I've tried going under properties -> librarian -> additional dependencies. All of these end with the PhysicsCore project failing to compile due to missing procedures and modules.
I have gotten it to work one way that isn't very helpful. I have added a new project to the solution and then added in all of the '.obj' and '.mod' files and the '.lib' file. Changed the solution settings to not rebuild that project. And then finally added that non-building project as a dependency of the PhysicsCore project.
I feel like I must just be missing something small.
EDIT: years later. I finally came across the issue. If the library were all in .f90 files everything would work fine, but I'm using modules which require the .mod files. Everything was doing what it was supposed to as far as I can tell; however, it didn't behave the way I expected it to.
There are several ways:
Drag the .lib into the project as a source file. You say this didn't work, but it always has when I have done it.
In the Linker project properties, add the full path to the .lib to Linker > Input > Additional Dependencies, or just add the .lib name there and add the directory path to Linker > General > Additional Library Directories.
If the parent project is also Fortran, right click on the parent project, select Build Dependencies > Project Dependencies. Check the box for the library project. (This does not work if the parent project is not Fortran.)
I would generally recommend #3, as this will also make the .mod files from the library project visible to the parent project. If you choose one of the other methods, you then also have to make any include or .mod files visible by adding the directory path to the project property Fortran > General > Additional Include Directories.
If you need more help with this, I suggest asking in https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows
I am creating a library for Mac using XCode5 which is using some code (c++) that is being developed and maintained by other developer and is at a different path than my library project.
e.g. my project is at /svntrunk/../../mylibraryproject/
The code I want to compile(use) in my library is at
/svntrunk/../../../utils/networkutils/src/source files here
I have tried following approaches
Refer the source files into my project but don't copy them into my project, that way when the other developer updates his code that is automatically reflected since I am pointing to his location. But in this case the linker fails to find the symbols from networkutils code.
Here while adding the file to the project I don't select 'Copy items ..' option
Second approach I took is to select 'Copy items..' option while adding the source files from networkutils to my project. This way the files is copied to my project and the compiler is able to find the symbols. But now if the other developer updates networkutils code I have to manually copy the updated code files which doesn't seem to be right thing to do.
It seems that to move forward I will have to go with option 2. Please let me know if there is a better way to approach this problem.
Thanks
Dev
If he's developing using Xcode as well and has a project, you could link to the project, build that as a lib and include it in the build dependencies in your project.
I do this for Cocos2d.
Failing that, I would pursue option 1 and try to figure out why it's not finding the symbols. Are you sure you have the correct headers included? One reason the compiler fails to find symbols is that you're using functions whose headers are not included.
Extra info here:
https://stackoverflow.com/a/17415609/290072
For the last two years I have been using Java and NetBeans, where all I need to do to add a new third party library to my project is throw in the .jar file and NetBeans does the rest.
Recently I have switch to C++ and Visual Studio and I am having a really hard time getting a project to compile using OpenGL, GLUT and GLEW due to 'Missing reference' errors.
Some tutorials tell me I need to download the projects for GLUT/GLEW and run them (that didn't work), some tutorials tell me I need to add a .dll file to my Win32 folder, others say just put the header files in the same directory as your project and some say I need to install these libraries in to Visual Studio itself, not just to my project.
None of these approaches have worked thus far.
All I want is for this one project to use these libraries. This is throwing a major spanner in the works for me at the moment, any help would be appreciated.
Sorry, I don't have an easy answer for you. I've been using OpenGL on Windows for years, and it can be a pain.
MS doesn't even (really) support OpenGL, the headers that come with Windows are the old 1.x ones - and they have no plans on changing that (they want to you use DX).
So, I would start small.
First, get a basically empty Win32 console "Hello World" app running.
Then, just add one component, like Glut.
Then, do the same - keeping it compiling / linking - incrementally add other components.
Wherever they tell you to put headers, libraries, DLLs, etc, it needs to be reflected in your project file. So:
add the location of the header files to "C/C++->Additional Include Directories"
add the .lib files to the "Linker->Input->Additional Dependencies"
(it still won't find them so) add the location of the .lib files to "Linker->General->Additional Library Directories"
With all that in place it should compile and link, but may not run still because it can't find the DLLs (that go along with the .lib files).
The shortest path to getting running might just be to dump the DLLs in the Windows/System32 folder. But in the long run that can be problematic as other apps may overwrite it (or see you as overwriting theirs).
What I do with specific DLLs is just load them explicitly in my application so I know for sure what DLL I'm getting (I don't do much Windows-specific GL, but when I did, I had my own \OpenGL directory with the versions of .h files, libs and DLLs I wanted).
Good Luck!
Oh, LoadLibrary() will load a DLL, etc.
cant seem to find a definintive answer to how to add a library. theres project properties with a whole bunch of places to add filepaths but im wondering if i shouldnt be editing all of them, can someone tell me the purpose of each possible entry, if there are more, and possibly which ones i should be editing? or a handy tutoril? ill list what entries i know about. currently trying to add the Wwise library.
project->project name properties->configuration properties->vc++
directories->library directories (click edit and addthe relevant
filepath)
project->project name properties->configuration
properties->linker->general->additional library dependencies (click
edit and addthe relevant filepath)
project->project name properties->configuration
properties->linker->input->additional dependencies (enter the names
of the libraries manually)
If i go through all that i get more linker errors than i started with
Those are the directories that the linker will search for .libs that are provided with Visual Studio. Like the CRT, MFC, ATL and the Windows SDK. You don't want to tinker with that one, the default value is read from the registry and was written there by the installer. Only change if you want to link to non-standard versions of these .libs
Those are the files that the linker will actually link.
Those are the additional directories that the linker will search for files that were specified in bullet 2 or from #pragma comment directives in the source code. You'll only need to set this if bullet 2 didn't specify the full path of the file or the .lib file isn't present in one of the VS standard directories or the project directory. You typically put the Boost install directory there for example.
So bullet 2 is the important one, that actually specifies what will be linked. Bullet 3 just helps the linker find the file.
So I used the VisualMagick tool to set up a Static Library project and compiled all of the ImageMagick Source to static lib files. Then I created a new solution and moved all those libs and the needed .h files to my lib folder in my new solution. My cpp file that I want to use the lib files compiles fine, even with #include Magick++.h in the header, until I add any references to things in imageMagick. Like if I say Magick::Image image; It will give me LNK1120. I have added the lib folder to my projects Additional Library Locations (or something like that) in the solution properties. I am new to the whole Linking language thing, coming mostly from a Python/Java background. Any suggestions? I have tried a brute google search and tried a lot of the suggestions I have seen.
I'll put the foregoing comments interchange in the form of a real answer:
To convince VS20xx to link your app with some non-standard library, including maybe a new library that you just built:
Under the VS main-menu "Project" tab, take "<your-project-name> Properties ..." and then
First, tell the linker where to look for a lib (like make -L):
Linker --> General
In the "Additional Library Directories" edit box, give the paths -- just the directories -- where lib files live.
Second, tell the linker what library files you want to lilnk with (like make -l):
Linker --> Input and then
In the "Additional Dependencies" edit box, add the space-separated unadorned lib-file name(s), no quotes needed, like:
Additional Dependencies mysqlclient.lib libcurl.lib mynewlib.lib
That should be it. (yeah, suuuuuuuuure :-)