mrfearless / libraries

Collection of libraries for use with x86 / x64 assembler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Symbols are automatically exported?

RCECoder opened this issue · comments

Refrencing any symbol from this library resulting in exporting this whole lib symbols in the output exe.
Is that normal?

Which library are you referring to? Some are third party. Others that are created by myself may include some or all of the functions, depending on how the library was created or intended for use.

Sorry, i don't know why my topic went under general. I was referring to CJSON. I have also tried LZ4, it has the same issue.
Reference any symbol of those lib will cause exporting whole symbols in the exe.

Most libraries are compiled that way - only if they are compiled with separate obj files for each individual function before adding into the library, then the linker only pull specific symbols. A few of my libraries are created that way - treeview, listview etc - each asm file is assembled into obj and then put into the library. Other third party libraries probably just compile to just one obj which will contain the full symbols. It might be possible to change some visual studio setting to create separate obj files, but its not something i'm aware of.

In cJSON, for example, is just one large cJSON.c file that contains all the functions - when that's compiled to a static library all the functions are going to be in it, and as the functions are not separated when you reference one symbol, the entire amount is included.

Hi fearless,
No that is not how it works. A symbol is not exported by default, it has to be explicitly exported.
I have compiled the library and had to use #define CJSON_HIDE_SYMBOLS 1 for it to disable symbol exporting.

CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol

This controls the CJSON_PUBLIC that is preceding every symbol.


#elif defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_PUBLIC(type)   __declspec(dllexport) type CJSON_STDCALL

Also, consider using statically linked msvcrt by using /MT. It is better that way.
Hope that helps.

Thanks @TOW87, I didn't see that option, but have enabled it now and also added msvcrt.lib to the additional dependencies with the /MT - will update soon. For the LZ4 library I did also look at that and found that maybe #define LZ4_DLL_EXPORT 0 would work (as well as adding msvcrt.lib /MT) - have to download and update to the latest version anyhow as I was getting some warnings with the x64 build.