Static Library

Noob question - sorry for that!

I created a static library (.lib) with some basical functions. Creating another project (a simple console project) I added this library and its single header file with declarations. However my declarations got a warning for each. Without this header file I cannot call the static library's functions...
Maybe I missed something - or I do something wrong. Any help?

What's the compiler used - and what's the warnings provided.
Did you use #pragma once and/or wrap the header file in #ifndef #define #endif ?

Actually, I'm guessing it's a linking issue, did you add the reference in the project?

What IDE are you using? Here's the walkthrough on Windows Visual Studio:
https://learn.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-static-library-cpp?view=msvc-170#CreateAppToRefTheLib

Any well established IDE should have similar tutorials, but the steps will be similar, the IDE must tell the Compiler where to find that new lib file since it might not be in the regular build directory.
Last edited on
I am wrong. This is not literally a warning. This is the little wavy green line on a declaration which has no definition. Sorry for the bad explanation. I am using VS 2022. I have #pragma once. The program works fine as expected. Some say that Intellisense can be quirky ++
Last edited on
Woops, and I misread "warning" as error and assumed the program wasn't compiling...
No it works fine as expected. The link with the library is done, but I have some green lines under functions' declarations. It's not a problem, but I don't understand why. No warning no error ++
I don't have Visual Studio (I'm a Linux geek). But I know having green squiggles would drive me insane. Looks like there's a way to turn them down:

Here is a quick solution for me. Go to Tools->Options->Environments->Font and Colors->Warning. Then change the color to match your background color. The squiggles are gone but when you mouse over the syntax, it'll still display the warning as tooltip. I like this way better as most of the warnings are useless to me.
Found above quote at https://developercommunity.visualstudio.com/t/green-squiggles/385489
I hope there's an option for just the green squiggles.

Part 2:
On another site they say that green is good and it means that you can add them to intelisense's library, but I didn't find a way to do that. Does an option like that pop up if you right-click it?
Last edited on
turning off intellisense warnings cuts down on a lot of bugged up reporting and nonsense. The normal C++ warnings are much easier to manage and more useful.
Hum... I would like to keep Intellisense into my solution. This is an useful tool which often helps me.
No it works fine as expected. The link with the library is done, but I have some green lines under functions' declarations. It's not a problem, but I don't understand why. No warning no error ++

All three mainstream compilers have functionality to suppress diagnostics that originate in third-party code. For cl.exe you probably want to use /external:
https://learn.microsoft.com/en-us/cpp/build/reference/external-external-headers-diagnostics?view=msvc-170
Admittedly I don't know for sure whether /external works with intellisense in particular. I don't use VS (though I do use cl.exe) because it's painfully slow and crashes frequently.

For clang++ or g++ you may be able to use -isystem.
https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html

If these options don't work you can use various pragmas to suppress warnings. A typical example could be:
1
2
3
4
5
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-enum"
#include "some-offending-header.hpp"
void f() { switch (::e) { /* some more offending code */ } }
#pragma GCC diagnostic pop 

Last edited on
intelisense is great: it fills in members and gives mouse over hints and such.
intelisense warnings are junk: they add a bunch of bugged up complaints about non-issues. My current project for example has complaints about functions that use a few KB of stack space, valid enums that are not the gimpy enum class, and other complete nonsense. To date not a single one of them has been useful. A small # of them are probably correct for ultra pedantic code, but remember, this is microsoft complaining that you didn't use an enum class while they have redefined bool and every integer type 3 times over, hidden pointers behind typedefs, offer get functions that are type void and return in the parameter (making you need an extra statement frequently, instead of foo(func()) you have to say type tmp; func(tmp); foo(tmp); ), and has hundreds of other rubbishisms.
but I have some green lines under functions' declarations


If you hover the mouse over one it should show a warning number and a brief explanation.
Last edited on
If you hover the mouse over one it should show a warning number and a brief explanation.

A classical explanation : a definition for this declaration cannot be found...
Last edited on
Topic archived. No new replies allowed.