{"action":"created","issue":{"url":"https://api.github.com/repos/UW-Hydro/VIC/issues/790","repository_url":"https://api.github.com/repos/UW-Hydro/VIC","labels_url":"https://api.github.com/repos/UW-Hydro/VIC/issues/790/labels{/name}","comments_url":"https://api.github.com/repos/UW-Hydro/VIC/issues/790/comments","events_url":"https://api.github.com/repos/UW-Hydro/VIC/issues/790/events","html_url":"https://github.com/UW-Hydro/VIC/issues/790","id":322484098,"number":790,"title":"multiple definition error when referenced by c++","user":{"login":"Sibada","id":14119579,"avatar_url":"https://avatars1.githubusercontent.com/u/14119579?v=4","gravatar_id":"","url":"https://api.github.com/users/Sibada","html_url":"https://github.com/Sibada","followers_url":"https://api.github.com/users/Sibada/followers","following_url":"https://api.github.com/users/Sibada/following{/other_user}","gists_url":"https://api.github.com/users/Sibada/gists{/gist_id}","starred_url":"https://api.github.com/users/Sibada/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sibada/subscriptions","organizations_url":"https://api.github.com/users/Sibada/orgs","repos_url":"https://api.github.com/users/Sibada/repos","events_url":"https://api.github.com/users/Sibada/events{/privacy}","received_events_url":"https://api.github.com/users/Sibada/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-05-12T05:22:35Z","updated_at":"2018-05-18T08:48:18Z","closed_at":null,"author_association":"NONE","body":"- VIC version 5.0.1 February 1, 2017\r\n- gcc 4.9.3; g++ 4.9.3\r\n- MinGW of RBuildTools 3.3\r\n\r\n#### Feature Requests\r\nI try to write an c++ extension of VIC to make it could be called by R easier. I found that some global variables were definited in the head files, including `char vic_run_ref_str[MAXSTRING];` at line 95 of file `vic/vic_run/include/vic_def.h`, `FILE *LOG_DEST;` at line 61 of file `vic/vic_run/include/vic_log.h`, and `double (*funcd)(double z, ...` at line 177 of file `vic/vic_run/include/vic_run.h`.\r\nIt causes multiple definition error when I let several cpp files include the `vic_run.h`.\r\nIt seems to solved when I take them into a c file and place `extern` to their original definitions. Might it be proper?"},"comment":{"url":"https://api.github.com/repos/UW-Hydro/VIC/issues/comments/390139963","html_url":"https://github.com/UW-Hydro/VIC/issues/790#issuecomment-390139963","issue_url":"https://api.github.com/repos/UW-Hydro/VIC/issues/790","id":390139963,"user":{"login":"Sibada","id":14119579,"avatar_url":"https://avatars1.githubusercontent.com/u/14119579?v=4","gravatar_id":"","url":"https://api.github.com/users/Sibada","html_url":"https://github.com/Sibada","followers_url":"https://api.github.com/users/Sibada/followers","following_url":"https://api.github.com/users/Sibada/following{/other_user}","gists_url":"https://api.github.com/users/Sibada/gists{/gist_id}","starred_url":"https://api.github.com/users/Sibada/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sibada/subscriptions","organizations_url":"https://api.github.com/users/Sibada/orgs","repos_url":"https://api.github.com/users/Sibada/repos","events_url":"https://api.github.com/users/Sibada/events{/privacy}","received_events_url":"https://api.github.com/users/Sibada/received_events","type":"User","site_admin":false},"created_at":"2018-05-18T08:48:18Z","updated_at":"2018-05-18T08:48:18Z","author_association":"NONE","body":"@jhamman Those revises are applied on the master branch, might I should revise them on the develop branch and open the PR?\r\nMy revises includes add an `extern` to the h files:\r\n```C\r\n// vic/vic_run/src/vic_def.h\r\nextern size_t NR;       /**< array index for force struct that indicates\r\n                             the model step avarage or sum */\r\nextern size_t NF;       /**< array index loop counter limit for force\r\n                             struct that indicates the SNOW_STEP values */\r\nextern char   vic_run_ref_str[MAXSTRING];\r\n\r\n// vic/vic_run/src/vic_run.h\r\nextern double (*funcd)(double z, double es, double Wind, double AirDens, double ZO,\r\n                double EactAir, double F, double hsalt, double phi_r,\r\n                double ushear,\r\n                double Zrh);\r\n\r\n// vic/vic_run/src/vic_log.h\r\nextern FILE *LOG_DEST;\r\n```\r\nAnd move the definitions to a c file:\r\n```C\r\n// my_R_package/src/global.c\r\nsize_t              NR;\r\nsize_t              NF;\r\n\r\nFILE *LOG_DEST;\r\nchar vic_run_ref_str[MAXSTRING];\r\n\r\ndouble (*funcd)(double z, double es, double Wind, double AirDens, double ZO,\r\n        double EactAir, double F, double hsalt, double phi_r,\r\n        double ushear,\r\n        double Zrh);\r\n```\r\n\r\nI also found that some C std library functions have no implements in windows platform, whatever VC or MinGW are used, including `strptime`, `backtrace` and `backtrace_symbols`.\r\nI though in the R package some macro defines should be used like:\r\n```C\r\n// vic/drivers/shared_all/src/vic_log.c\r\nvoid\r\nprint_trace(void)\r\n{\r\n#ifndef _WIN32\r\n    void  *array[50];\r\n    size_t size;\r\n    char **strings;\r\n    size_t i;\r\n\r\n    size = backtrace(array, 50);\r\n    strings = backtrace_symbols(array, size);\r\n\r\n    /* Note: we are ignoring the first and last stack frame\r\n       the first is this function, the last is the linker, neither are\r\n       particularly useful */\r\n    fprintf(LOG_DEST,\r\n            \"---------------------------------------------------------------------------\\n\");\r\n    fprintf(LOG_DEST, \"Traceback (most recent call last):\\n\");\r\n    for (i = size - 2; i > 0; i--) {\r\n        fprintf(LOG_DEST, \"%s\\n\", strings[i]);\r\n    }\r\n\r\n    free(strings);\r\n#endif\r\n}\r\n```\r\nAnd the `strptime` also needs a specified implement.\r\n"}}
{"actor":{"display_login":"Sibada"}}