Archived

This topic is now archived and is closed to further replies.

cozman

inline & libraries

Recommended Posts

cozman    583
I have been using a static library for my code, in what I consider my personal library, it''s been very handy on my latest project until tonight when I decided to inline some basic things, and I found a pile of linking errors waiting for me. I realize that it makes sense that when using a library inlining doesn''t work, but I was wondering if there were any solutions. Is it entirely impossible to inline code that is in a static lib, or is there some way to keep using a lib, but also inline my needed functions.

Share this post


Link to post
Share on other sites
Lord Bart    226
Hello cozman,

If you want to use inline methods that exist in the lib you are linking to.
I belive what you would need to do is have a #ifdef test around the inline and non inline method.

#ifdef(_USE_INLINE_)
inline int test { return 1; }
#else
int test();
#endif

So when you have _USE_INLINE_ defined the compiler will put in the inline code. When it is not defined the compiler put in a function call.

Now you still might have problems at link time but not sure.
Since compiler puts actual code in place of the inline should not have a problem.
Execpt in debug were it keeps the name and other info around for the inline so you can go to it in debugger window or set break point.
Then you might get a link error saying something like more then one reference, if this happens see if there is a linker flag that tell linker to use first reference for method.

Lord Bart

Share this post


Link to post
Share on other sites
Oluseyi    2103
quote:
Original post by cozman
Is it entirely impossible to inline code that is in a static lib...
Not theoretically, but I don''t know of any compiler that supports it. Inlining isn''t that important anyway; the compiler is free to ignore you (except using compiler-specific techniques like __forceinline for MSVC).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Put the inline functions in the header files so that the compiler knows what to inline in each unit. Although I suppose in some ways this undermines the point of the library file

Share this post


Link to post
Share on other sites
davepermen    1047
the newest intel and microsoft compilers (gcc, too?) can do whole project optimisations, means, the linker can analyse and inline functions, too.. that way, inline got 100% deprecated as a keyword, and is useless. on the other hand, linking with static libraries gives you the same performance, as compiling directly with the .cpp files..

about the same, at least..


or so the marketing told me:D




If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net

Share this post


Link to post
Share on other sites
cozman    583
I have functions which simply make one OpenGL call, and some of them are called quite often. For example I have a color struct/class, and it has a method, MakeGLColor, which simply calls glColor4ub(mRed,mGreen,mBlue,mAlpha) these are the main functions I''m inlining, if I drop the ''inline'' before them would it be better for me to simply replace all calls to MakeGLColor with calls to glColor4ub, or would the speed difference not make a signifigant difference (I am calling these quite a bit at the moment.)

Share this post


Link to post
Share on other sites