Dear members,
How can I include “map” and “string” into C++ static library?
Br
Dear members,
How can I include “map” and “string” into C++ static library?
Br
I am using gcc V 6.3.0 and I have included all the necessary directories for map
I have also included the headres of map and string
but why I am still getting the following errors?
the tool tip was showing namespace for map as __debug
I tried using that as well
then the error changes to
please help me to figure this out.
Thnaks and regards
Ashamdeep Singh Saini
Hi @ashamdeep.saini ,
I am usually not using C++ nor doing static libs but I made your example work for me here partially. (Please note that next time posting a minimal working/non-working example code either as text or as file would help people to try to fix code instead of rewrite it from scratch )
The sections in the help I used for reference:
https://help.br-automation.com/#/en/4/libraries%2Flibraries%2Fprogrammingmodel_libraries_static.html
https://help.br-automation.com/#/en/4/programming%2Fprograms%2Fansic%2Fprogrammingmodel_programs_ansicpp_specific.html
Code:
#include <bur/plctypes.h>
#ifdef __cplusplus
extern "C"
{
#endif
#include "Library.h"
#ifdef __cplusplus
};
#endif
#include <map>
#include <string>
unsigned long bur_heap_size = 0xFFFFF;
using namespace std;
/* TODO: Add your comment here */
void Encode(struct Encode* inst)
{
/*TODO: Add your code here*/
map<string, int> enMp;
enMp["(sp)"] = 32;
}
Attached please find a full project export:
cpptest.zip (76.4 KB)
The only tests I did was compile testing, I did not call the function anywhere or test any more than that, but I think it does the job
Best regards
Michael
Dear Michael,
Thanks a lot.
Sorry about not posting the entire code it wasn’t cooked properly. but will do next time.
so silly of me , I was using extention “.c” instead of “.Cpp”.
by default we get only option of ANSI C not for Cpp
further when I tried to call the function block into the program (using the same project that you have sent)
following flood of errors appeared.
is it compiler related issue? and how to fix this?
Thanks and regards
Hi,
the answer to your current issue can also be found in the help (same chapter as linked already)
https://help.br-automation.com/#/en/6/libraries%2Flibraries%2Fprogrammingmodel_libraries_static.html
Quote:
Statically bound ANSI C/C++ libraries are defined as such solely by the absence of any IEC declaration files.
ANSI C++ libraries can be used exclusively from C++ programs.
Once you follow that, it compiles just fine.
Note that the bur_heap_size variable may only be defined in either the lib or the task(I kept it in the lib). Inserting a C++ Task already inserts the line, resulting in a compiler error in that regard. Delete the line - Done
Best regards
Thanks Michael,
I should have read this earlier.