My static library project is somehow related with my 'test' project

Feb 7, 2016 at 9:44pm
Hello.

I've made my own Static Library project on Visual Studio.

The problem is this: unless I personally test the code in another separately created project, I'm not able to catch errors.

An example?

In my library I added a class that includes the iostream header file.
Somewhere in the class, I used COUT and ENDL... but I forgot to write using namespace std;

Well, the compiler didn't complain.
I used my Class in a separate project (simulating the project of a programmer that installs my library on his computer).

Well, since in my 'test project' I wrote the using namespace std;,
the program runs.

The problem is, when I erase that using directive, well at that point I get an error from the compiler.

This because I'm including the header of my library in my project, so the compiler gets all the code as if it was just one translation unit.

I want my compiler to be able to catch and warn me of those errors in my LIBRARY project.

If I forgot the using directive in my LIBRARY project, I want the compiler to warn me there!

Thanks for the reply in advance!
Feb 7, 2016 at 9:46pm
So in short, i don't want the programmer who installs my library to actually get errors related to my library.

Those are errors I want to see in my library project!
Feb 7, 2016 at 10:57pm
Two things:

Do you, by chance, have using directives in some of your header files?

And, do you #include your library header files before standard includes in your library project?
Last edited on Feb 7, 2016 at 10:59pm
Feb 7, 2016 at 11:02pm
My static library is composed by the main header file "gedamial.h" which basically includes other header files "GArray.h", "GString.h" and such.

Some of those include the <iostream> header file.

In my 'test project' i just include the main header file, "gedamial.h"

>Do you, by chance, have using directives in some of your header files?<
No
Last edited on Feb 7, 2016 at 11:03pm
Feb 7, 2016 at 11:49pm
If your static library is made of header files, it isn't a static library. It's a handful of header files, and errors in those header files will only be found when they are compiled as part of something that uses them, just like any header file.
Feb 7, 2016 at 11:54pm
Depending on how the user of your library uses your header files, you may or may not get your wish. The user can have the library headers treated specially by the compiler, suppressing warnings, but it's their choice.
Feb 8, 2016 at 7:48am
@Moschops that's not completely true. If I declare a new string variable without specifying std:: I get error in the library project at compile time.

With cout and endl this is not happening though.
Feb 8, 2016 at 10:40am
If your library is made entirely of header files, there is nothing to compile in it. There is no compile time.
Feb 8, 2016 at 11:08am
It turned out something, maybe that's the reason:

Template functions DON'T compile until we use/call them.

Screenshot: http://prntscr.com/a0i4y3

SHOULD generate errors, but it doesn't since it's a template function.

So, same thing happens if I use cout without the using directive of std

With that said, what is a good tip to catch errors in these cases where the compiler is silent?
Feb 8, 2016 at 11:43am
The compiler is silent if it never sees the code. So make it compile the code, and then it will see the code and then it will not be silent. For example, create a single main function that uses the template library functions so that they have to be created so the compiler has to look at them.
Feb 8, 2016 at 12:42pm
Thanks to everyone ;)
Topic archived. No new replies allowed.