mcaceresb / stata-honestdid

Robust inference in difference-in-differences and event study designs (Stata version of the R package of the same name)
70 stars 18 forks source link

Issues with compilation #22

Closed HamWham closed 3 months ago

HamWham commented 3 months ago

Hello, I am attempting to build the plugin. I encountered a few issues but the most recent I'm having a hard time getting past. I'm using cmake/3.22.4 and gcc/11.2.0 on RHEL7.9.

I initially encountered this error:

[100%] Built target osqp_codegen_demo
Compiling honestdid plugin
    with flags -shared -fPIC -DSYSTEM=OPUNIX
rm -f src/build/honestosqp_unix.plugin src/build/honestecos_unix.plugin
gcc -Wall -O3 -shared -fPIC -DSYSTEM=OPUNIX -I./osqp/include -I./osqp/build/include/public -o src/build/honestosqp_unix.plugin src/plugin/honestosqp.c src/plugin/stplugin.c ./osqp/build/out/libosqp.a
src/plugin/honestosqp.c:8:10: fatal error: osqp.h: No such file or directory
    8 | #include "osqp.h"
      |          ^~~~~~~~
compilation terminated.
make: *** [honestosqp] Error 1
rm -f src/build/honestosqp_unix.plugin src/build/honestecos_unix.plugin
gcc -Wall -O3 -shared -fPIC -DSYSTEM=OPUNIX -I./osqp/include -o src/build/honestosqp_unix.plugin src/plugin/honestosqp.c src/plugin/stplugin.c ./osqp/build/out/libosqp.a
src/plugin/honestosqp.c:8:10: fatal error: osqp.h: No such file or directory
    8 | #include "osqp.h"
      |          ^~~~~~~~
compilation terminated.
make: *** [honestosqp] Error 1
Plugin compiletion failed; please report issue

I found the header file in two locations and checked to make sure they were the same (they were):

[owj5641@quser34 stata-honestdid]$ pwd -P
/projects/a9009/owj5641/tickets/182880/stata-honestdid
[owj5641@quser34 stata-honestdid]$ find . -type f -name osqp.h
./osqp/include/public/osqp.h
./osqp/build/codegen_src/inc/public/osqp.h
[owj5641@quser34 stata-honestdid]$ diff ./osqp/include/public/osqp.h ./osqp/build/codegen_src/inc/public/osqp.h

I adjusted compile.sh to include ./osqp/include/public:

if (( ${RUN_BUILD} )); then
    make all OSQP_H="./osqp/include -I./osqp/include/public" OSQP_A=./osqp/build/out/libosqp.a ECOS_H="./ecos/include \
-I./ecos/external/SuiteSparse_config" ECOS_A="./ecos/libecos.a ./ecos/libecos_bb.a" ${HONEST_OUT} OSFLAGS="${HONEST_FLAGS}"

I then get the following error, and go through the same exercise of adding the header file location to the make line:

[100%] Built target osqp_codegen_demo
Compiling honestdid plugin
    with flags -shared -fPIC -DSYSTEM=OPUNIX
rm -f src/build/honestosqp_unix.plugin src/build/honestecos_unix.plugin
gcc -Wall -O3 -shared -fPIC -DSYSTEM=OPUNIX -I./osqp/include -I./osqp/include/public -o src/build/honestosqp_unix.plugin src/plugin/honestosqp.c src/plugin/stplugin.c ./osqp/build/out/libosqp.a
In file included from src/plugin/honestosqp.c:8:
./osqp/include/public/osqp.h:6:11: fatal error: osqp_configure.h: No such file or directory
    6 | # include "osqp_configure.h"
      |           ^~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [honestosqp] Error 1
Plugin compiletion failed; please report issue

if (( ${RUN_BUILD} )); then make all OSQP_H="./osqp/include -I./osqp/include/public -I./osqp/build/include/public" OSQP_A=./osqp/build/out/libosqp.a \ ECOS_H="./ecos/include -I./ecos/external/SuiteSparse_config" ECOS_A="./ecos/libecos.a ./ecos/libecos_bb.a" ${HONEST_OUT} \ OSFLAGS="${HONEST_FLAGS}"

Now it seems to find all of the header files it is looking for but I get a slew of other errors:


[100%] Built target osqp_codegen_demo
Compiling honestdid plugin
    with flags -shared -fPIC -DSYSTEM=OPUNIX
rm -f src/build/honestosqp_unix.plugin src/build/honestecos_unix.plugin
gcc -Wall -O3 -shared -fPIC -DSYSTEM=OPUNIX -I./osqp/include -I./osqp/include/public -I./osqp/build/include/public -o src/build/honestosqp_unix.plugin src/plugin/honestosqp.c src/plugin/stplugin.c ./osqp/build/out/libosqp.a
In file included from src/plugin/honestosqp.c:9:
src/plugin/honestosqp.h:18:50: error: unknown type name ‘c_float’; did you mean ‘ST_float’?
   18 | ST_retcode honestosqp_read_vector(char **bufptr, c_float **x, c_int *nn);
      |                                                  ^~~~~~~
      |                                                  ST_float
src/plugin/honestosqp.h:18:63: error: unknown type name ‘c_int’; did you mean ‘u_int’?
   18 | ST_retcode honestosqp_read_vector(char **bufptr, c_float **x, c_int *nn);
      |                                                               ^~~~~
      |                                                               u_int
src/plugin/honestosqp.h:19:50: error: unknown type name ‘c_float’; did you mean ‘ST_float’?
   19 | ST_retcode honestosqp_read_matrix(char **bufptr, c_float **A, c_int **i, c_int **p, c_int *A_nnz);
      |                                                  ^~~~~~~
      |                                                  ST_float
src/plugin/honestosqp.h:19:63: error: unknown type name ‘c_int’; did you mean ‘u_int’?
   19 | ST_retcode honestosqp_read_matrix(char **bufptr, c_float **A, c_int **i, c_int **p, c_int *A_nnz);
      |                                                               ^~~~~
      |                                                               u_int
src/plugin/honestosqp.h:19:74: error: unknown type name ‘c_int’; did you mean ‘u_int’?
   19 | ST_retcode honestosqp_read_matrix(char **bufptr, c_float **A, c_int **i, c_int **p, c_int *A_nnz);
      |                                                                          ^~~~~
      |                                                                          u_int
src/plugin/honestosqp.h:19:85: error: unknown type name ‘c_int’; did you mean ‘u_int’?
   19 | ST_retcode honestosqp_read_matrix(char **bufptr, c_float **A, c_int **i, c_int **p, c_int *A_nnz);
      |                                                                                     ^~~~~
      |                                                                                     u_int
src/plugin/honestosqp.h:20:1: error: unknown type name ‘c_int’; did you mean ‘u_int’?
   20 | c_int      honestosqp_read_int(char **bufptr);
      | ^~~~~
      | u_int
src/plugin/honestosqp.c: In function ‘honestosqp’:
src/plugin/honestosqp.c:37:5: error: unknown type name ‘c_int’; did you mean ‘u_int’?
   37 |     c_int verbose, n, m, i;
      |     ^~~~~
      |     u_int
src/plugin/honestosqp.c:38:5: error: unknown type name ‘c_int’; did you mean ‘u_int’?
   38 |     c_int P_nnz, A_nnz;
      |     ^~~~~
      |     u_int
src/plugin/honestosqp.c:39:5: error: unknown type name ‘c_float’; did you mean ‘ST_float’?
   39 |     c_float *P_x = NULL, *A_x = NULL;
      |     ^~~~~~~
      |     ST_float
src/plugin/honestosqp.c:40:5: error: unknown type name ‘c_int’; did you mean ‘u_int’?
   40 |     c_int   *P_i = NULL, *A_i = NULL;
      |     ^~~~~
      |     u_int
src/plugin/honestosqp.c:41:5: error: unknown type name ‘c_int’; did you mean ‘u_int’?
   41 |     c_int   *P_p = NULL, *A_p = NULL;
      |     ^~~~~
      |     u_int
src/plugin/honestosqp.c:42:5: error: unknown type name ‘c_float’; did you mean ‘ST_float’?
   42 |     c_float *q = NULL, *u = NULL, *l = NULL;
      |     ^~~~~~~
      |     ST_float
src/plugin/honestosqp.c:48:48: warning: implicit declaration of function ‘c_malloc’; did you mean ‘calloc’? [-Wimplicit-function-declaration]
   48 |     OSQPSettings  *settings = (OSQPSettings *) c_malloc(sizeof(OSQPSettings));
      |                                                ^~~~~~~~
      |                                                calloc
src/plugin/honestosqp.c:48:31: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
   48 |     OSQPSettings  *settings = (OSQPSettings *) c_malloc(sizeof(OSQPSettings));
      |                               ^
src/plugin/honestosqp.c:49:5: error: unknown type name ‘OSQPData’
   49 |     OSQPData      *data     = (OSQPData *)     c_malloc(sizeof(OSQPData));
      |     ^~~~~~~~
src/plugin/honestosqp.c:49:32: error: ‘OSQPData’ undeclared (first use in this function)
   49 |     OSQPData      *data     = (OSQPData *)     c_malloc(sizeof(OSQPData));
      |                                ^~~~~~~~
src/plugin/honestosqp.c:49:32: note: each undeclared identifier is reported only once for each function it appears in
src/plugin/honestosqp.c:49:42: error: expected expression before ‘)’ token
   49 |     OSQPData      *data     = (OSQPData *)     c_malloc(sizeof(OSQPData));
      |                                          ^
src/plugin/honestosqp.c:50:9: error: request for member ‘A’ in something not a structure or union
   50 |     data->A = NULL;
      |         ^~
src/plugin/honestosqp.c:51:9: error: request for member ‘P’ in something not a structure or union
   51 |     data->P = NULL;
      |         ^~
src/plugin/honestosqp.c:71:15: warning: implicit declaration of function ‘honestosqp_read_matrix’; did you mean ‘honestosqp_read_int’? [-Wimplicit-function-declaration]
   71 |     if ((rc = honestosqp_read_matrix(&bufptr, &P_x, &P_i, &P_p, &P_nnz))) goto exit;
      |               ^~~~~~~~~~~~~~~~~~~~~~
      |               honestosqp_read_int
src/plugin/honestosqp.c:74:15: warning: implicit declaration of function ‘honestosqp_read_vector’; did you mean ‘honestosqp_read_int’? [-Wimplicit-function-declaration]
   74 |     if ((rc = honestosqp_read_vector(&bufptr, &q, &n))) goto exit;
      |               ^~~~~~~~~~~~~~~~~~~~~~
      |               honestosqp_read_int
src/plugin/honestosqp.c:81:43: warning: overflow in conversion from ‘double’ to ‘int’ changes value from ‘-1.0e+30’ to ‘-2147483648’ [-Woverflow]
   81 |         if ( SF_is_missing(l[i]) ) l[i] = -OSQP_INFTY;
      |                                           ^
In file included from ./osqp/include/public/osqp.h:7,
                 from src/plugin/honestosqp.c:8:
./osqp/include/public/osqp_api_constants.h:173:22: warning: overflow in conversion from ‘double’ to ‘int’ changes value from ‘1.0e+30’ to ‘2147483647’ [-Woverflow]
  173 | #  define OSQP_INFTY ((OSQPFloat)1e30)        // infinity
      |                      ^
src/plugin/honestosqp.c:82:43: note: in expansion of macro ‘OSQP_INFTY’
   82 |         if ( SF_is_missing(u[i]) ) u[i] = OSQP_INFTY;
      |                                           ^~~~~~~~~~
src/plugin/honestosqp.c:125:13: error: request for member ‘n’ in something not a structure or union
  125 |         data->n = n;
      |             ^~
src/plugin/honestosqp.c:126:13: error: request for member ‘m’ in something not a structure or union
  126 |         data->m = m;
      |             ^~
src/plugin/honestosqp.c:127:13: error: request for member ‘P’ in something not a structure or union
  127 |         data->P = csc_matrix(data->n, data->n, P_nnz, P_x, P_i, P_p);
      |             ^~
src/plugin/honestosqp.c:127:19: warning: implicit declaration of function ‘csc_matrix’ [-Wimplicit-function-declaration]
  127 |         data->P = csc_matrix(data->n, data->n, P_nnz, P_x, P_i, P_p);
      |                   ^~~~~~~~~~
src/plugin/honestosqp.c:127:34: error: request for member ‘n’ in something not a structure or union
  127 |         data->P = csc_matrix(data->n, data->n, P_nnz, P_x, P_i, P_p);
      |                                  ^~
src/plugin/honestosqp.c:127:43: error: request for member ‘n’ in something not a structure or union
  127 |         data->P = csc_matrix(data->n, data->n, P_nnz, P_x, P_i, P_p);
      |                                           ^~
src/plugin/honestosqp.c:128:13: error: request for member ‘q’ in something not a structure or union
  128 |         data->q = q;
      |             ^~
src/plugin/honestosqp.c:129:13: error: request for member ‘A’ in something not a structure or union
  129 |         data->A = csc_matrix(data->m, data->n, A_nnz, A_x, A_i, A_p);
      |             ^~
src/plugin/honestosqp.c:129:34: error: request for member ‘m’ in something not a structure or union
  129 |         data->A = csc_matrix(data->m, data->n, A_nnz, A_x, A_i, A_p);
      |                                  ^~
src/plugin/honestosqp.c:129:43: error: request for member ‘n’ in something not a structure or union
  129 |         data->A = csc_matrix(data->m, data->n, A_nnz, A_x, A_i, A_p);
      |                                           ^~
src/plugin/honestosqp.c:130:13: error: request for member ‘l’ in something not a structure or union
  130 |         data->l = l;
      |             ^~
src/plugin/honestosqp.c:131:13: error: request for member ‘u’ in something not a structure or union
  131 |         data->u = u;
      |             ^~
src/plugin/honestosqp.c:150:35: error: ‘c_int’ undeclared (first use in this function); did you mean ‘u_int’?
  150 |         settings->max_iter     = (c_int) (SF_is_missing(max_iter)? 10000: max_iter);
      |                                   ^~~~~
      |                                   u_int
src/plugin/honestosqp.c:170:30: warning: passing argument 1 of ‘osqp_setup’ from incompatible pointer type [-Wincompatible-pointer-types]
  170 |         if ((rc = osqp_setup(&work, data, settings))) goto exit;
      |                              ^~~~~
      |                              |
      |                              OSQPWorkspace ** {aka struct OSQPWorkspace_ **}
In file included from ./osqp/include/public/osqp.h:9,
                 from src/plugin/honestosqp.c:8:
./osqp/include/public/osqp_api_functions.h:83:50: note: expected ‘OSQPSolver **’ but argument is of type ‘OSQPWorkspace **’ {aka ‘struct OSQPWorkspace_ **’}
   83 | OSQP_API OSQPInt osqp_setup(OSQPSolver**         solverp,
      |                             ~~~~~~~~~~~~~~~~~~~~~^~~~~~~
src/plugin/honestosqp.c:170:37: warning: passing argument 2 of ‘osqp_setup’ from incompatible pointer type [-Wincompatible-pointer-types]
  170 |         if ((rc = osqp_setup(&work, data, settings))) goto exit;
      |                                     ^~~~
      |                                     |
      |                                     int *
In file included from ./osqp/include/public/osqp.h:9,
                 from src/plugin/honestosqp.c:8:
./osqp/include/public/osqp_api_functions.h:84:50: note: expected ‘const OSQPCscMatrix *’ but argument is of type ‘int *’
   84 |                             const OSQPCscMatrix* P,
      |                             ~~~~~~~~~~~~~~~~~~~~~^
src/plugin/honestosqp.c:170:43: warning: passing argument 3 of ‘osqp_setup’ from incompatible pointer type [-Wincompatible-pointer-types]
  170 |         if ((rc = osqp_setup(&work, data, settings))) goto exit;
      |                                           ^~~~~~~~
      |                                           |
      |                                           OSQPSettings *
In file included from ./osqp/include/public/osqp.h:9,
                 from src/plugin/honestosqp.c:8:
./osqp/include/public/osqp_api_functions.h:85:50: note: expected ‘const OSQPFloat *’ {aka ‘const double *’} but argument is of type ‘OSQPSettings *’
   85 |                             const OSQPFloat*     q,
      |                             ~~~~~~~~~~~~~~~~~~~~~^
src/plugin/honestosqp.c:170:19: error: too few arguments to function ‘osqp_setup’
  170 |         if ((rc = osqp_setup(&work, data, settings))) goto exit;
      |                   ^~~~~~~~~~
In file included from ./osqp/include/public/osqp.h:9,
                 from src/plugin/honestosqp.c:8:
./osqp/include/public/osqp_api_functions.h:83:18: note: declared here
   83 | OSQP_API OSQPInt osqp_setup(OSQPSolver**         solverp,
      |                  ^~~~~~~~~~
src/plugin/honestosqp.c:171:30: warning: passing argument 1 of ‘osqp_solve’ from incompatible pointer type [-Wincompatible-pointer-types]
  171 |         if ((rc = osqp_solve(work))) goto exit;
      |                              ^~~~
      |                              |
      |                              OSQPWorkspace * {aka struct OSQPWorkspace_ *}
In file included from ./osqp/include/public/osqp.h:9,
                 from src/plugin/honestosqp.c:8:
./osqp/include/public/osqp_api_functions.h:111:41: note: expected ‘OSQPSolver *’ but argument is of type ‘OSQPWorkspace *’ {aka ‘struct OSQPWorkspace_ *’}
  111 | OSQP_API OSQPInt osqp_solve(OSQPSolver* solver);
      |                             ~~~~~~~~~~~~^~~~~~
src/plugin/honestosqp.c:173:24: error: invalid use of incomplete typedef ‘OSQPWorkspace’ {aka ‘struct OSQPWorkspace_’}
  173 |             x[i] = work->solution->x[i];
      |                        ^~
src/plugin/honestosqp.c:175:19: error: invalid use of incomplete typedef ‘OSQPWorkspace’ {aka ‘struct OSQPWorkspace_’}
  175 |         obj = work->info->obj_val;
      |                   ^~
In file included from src/plugin/honestosqp.c:7:
src/plugin/honestosqp.c:184:62: error: invalid use of incomplete typedef ‘OSQPWorkspace’ {aka ‘struct OSQPWorkspace_’}
  184 |         rc = rc | (SF_macro_save("___honestosqp_status", work->info->status));
      |                                                              ^~
src/plugin/stplugin.h:201:60: note: in definition of macro ‘SF_macro_save’
  201 | #define SF_macro_save(m,t)      ((_stata_)->macresave((m),(t)))
      |                                                            ^
src/plugin/honestosqp.c:200:28: warning: passing argument 1 of ‘osqp_cleanup’ from incompatible pointer type [-Wincompatible-pointer-types]
  200 |     if (work) osqp_cleanup(work);
      |                            ^~~~
      |                            |
      |                            OSQPWorkspace * {aka struct OSQPWorkspace_ *}
In file included from ./osqp/include/public/osqp.h:9,
                 from src/plugin/honestosqp.c:8:
./osqp/include/public/osqp_api_functions.h:133:43: note: expected ‘OSQPSolver *’ but argument is of type ‘OSQPWorkspace *’ {aka ‘struct OSQPWorkspace_ *’}
  133 | OSQP_API OSQPInt osqp_cleanup(OSQPSolver* solver);
      |                               ~~~~~~~~~~~~^~~~~~
src/plugin/honestosqp.c:202:17: error: request for member ‘A’ in something not a structure or union
  202 |         if (data->A) c_free(data->A);
      |                 ^~
src/plugin/honestosqp.c:202:22: warning: implicit declaration of function ‘c_free’; did you mean ‘cfree’? [-Wimplicit-function-declaration]
  202 |         if (data->A) c_free(data->A);
      |                      ^~~~~~
      |                      cfree
src/plugin/honestosqp.c:202:33: error: request for member ‘A’ in something not a structure or union
  202 |         if (data->A) c_free(data->A);
      |                                 ^~
src/plugin/honestosqp.c:203:17: error: request for member ‘P’ in something not a structure or union
  203 |         if (data->P) c_free(data->P);
      |                 ^~
src/plugin/honestosqp.c:203:33: error: request for member ‘P’ in something not a structure or union
  203 |         if (data->P) c_free(data->P);
      |                                 ^~
src/plugin/honestosqp.c: At top level:
src/plugin/honestosqp.c:226:50: error: unknown type name ‘c_float’; did you mean ‘ST_float’?
  226 | ST_retcode honestosqp_read_matrix(char **bufptr, c_float **A_x, c_int **A_i, c_int **A_p, c_int *A_nnz)
      |                                                  ^~~~~~~
      |                                                  ST_float
src/plugin/honestosqp.c:226:65: error: unknown type name ‘c_int’; did you mean ‘u_int’?
  226 | ST_retcode honestosqp_read_matrix(char **bufptr, c_float **A_x, c_int **A_i, c_int **A_p, c_int *A_nnz)
      |                                                                 ^~~~~
      |                                                                 u_int
src/plugin/honestosqp.c:226:78: error: unknown type name ‘c_int’; did you mean ‘u_int’?
  226 | ST_retcode honestosqp_read_matrix(char **bufptr, c_float **A_x, c_int **A_i, c_int **A_p, c_int *A_nnz)
      |                                                                              ^~~~~
      |                                                                              u_int
src/plugin/honestosqp.c:226:91: error: unknown type name ‘c_int’; did you mean ‘u_int’?
  226 | ST_retcode honestosqp_read_matrix(char **bufptr, c_float **A_x, c_int **A_i, c_int **A_p, c_int *A_nnz)
      |                                                                                           ^~~~~
      |                                                                                           u_int
src/plugin/honestosqp.c:272:50: error: unknown type name ‘c_float’; did you mean ‘ST_float’?
  272 | ST_retcode honestosqp_read_vector(char **bufptr, c_float **x, c_int *nn)
      |                                                  ^~~~~~~
      |                                                  ST_float
src/plugin/honestosqp.c:272:63: error: unknown type name ‘c_int’; did you mean ‘u_int’?
  272 | ST_retcode honestosqp_read_vector(char **bufptr, c_float **x, c_int *nn)
      |                                                               ^~~~~
      |                                                               u_int
src/plugin/honestosqp.c:298:1: error: unknown type name ‘c_int’; did you mean ‘u_int’?
  298 | c_int honestosqp_read_int(char **bufptr)
      | ^~~~~
      | u_int
src/plugin/honestosqp.c: In function ‘honestosqp_read_int’:
src/plugin/honestosqp.c:302:13: error: ‘c_int’ undeclared (first use in this function); did you mean ‘u_int’?
  302 |     return((c_int) n);
      |             ^~~~~
      |             u_int
src/plugin/honestosqp.c:302:19: error: expected ‘)’ before ‘n’
  302 |     return((c_int) n);
      |           ~       ^~
      |                   )
src/plugin/honestosqp.c:303:1: warning: control reaches end of non-void function [-Wreturn-type]
  303 | }
      | ^
make: *** [honestosqp] Error 1
Plugin compiletion failed; please report issue

Any help would be appreciated, thanks!

mcaceresb commented 3 months ago

@Hamlox My bad. Apparently OSQP is in active development and they've moved stuff around. If you change to their latest release and update the submodules it should work. I also changed the install script to do this. LMK if it works.

HamWham commented 3 months ago

That worked great, thank you so much!

HamWham commented 3 months ago

Closing as completed.