ImportC linking issue

confuzzled con at fuzzled.com
Fri Nov 11 03:15:17 UTC 2022


Wondering if someone can help me with this. Mr. Adam D. Ruppe got 
me 90% there, but I'm a little lost after reaching the 99% mark. 
I want to use XLSX I/O to manipulate excel spreadsheets.

I've cloned, built, and installed the library. And with the help 
of Adam, I am now able to import it and link to D program (as 
long as I'm not using anything from the lib). Wanted to continue 
the discussion with Adam, but I realize the announce forum isn't 
the place to ask for help.

Anyway, the library has two dependencies:

- [expat](http://www.libexpat.org/) (only for libxlsxio_read)
- [minizip](http://www.winimage.com/zLibDll/minizip.html) or 
libzip (libxlsxio_read and libxlsxio_write)

Since I'm on a Mac, I installed them using homebrew. In a demo.d 
file I have the following:

```d
import xlsxio_read;
import std.stdio;

pragma(lib, "libxlsxio_read.a");
pragma(lib, "libexpat.a");
pragma(lib, "libminizip.a");

string filename = "logistic_regression.xlsx";

void main (string[] args)
{
     if (args.length > 1)
         filename = args[1];

     xlsxioreader xlsxioread;

     writef("XLSX I/O library version %s\n", 
xlsxioread_get_version_string());
}
```

And in xlsxio_read.c (probably should call it something else), I 
simply import the library header:
```c
#include <xlsxio_read.h>
```

When I try to compile it, I get a slew of errors about undefined 
symbols. It wasn't finding libexpat and libminizip so I copied 
those to my work directory and tried again. With that, most of 
the errors disappeared. The remaining ones are:

```
dmd demo.d xlsxio_read.c
ld: warning: ignoring file libminizip.a, building for 
macOS-x86_64 but attempting to link with file built for 
macOS-x86_64
Undefined symbols for architecture x86_64:
   "_unzClose", referenced from:
       _xlsxioread_close in libxlsxio_read.a(xlsxio_read.c.o)
   "_unzCloseCurrentFile", referenced from:
       _expat_process_zip_file in libxlsxio_read.a(xlsxio_read.c.o)
       _xlsxioread_sheetlist_close in 
libxlsxio_read.a(xlsxio_read.c.o)
       _xlsxioread_sheet_close in libxlsxio_read.a(xlsxio_read.c.o)
   "_unzGetCurrentFileInfo", referenced from:
       _iterate_files_by_contenttype_expat_callback_element_start 
in libxlsxio_read.a(xlsxio_read.c.o)
   "_unzGetGlobalInfo", referenced from:
       _iterate_files_by_contenttype_expat_callback_element_start 
in libxlsxio_read.a(xlsxio_read.c.o)
   "_unzGoToFirstFile", referenced from:
       _iterate_files_by_contenttype_expat_callback_element_start 
in libxlsxio_read.a(xlsxio_read.c.o)
   "_unzGoToNextFile", referenced from:
       _iterate_files_by_contenttype_expat_callback_element_start 
in libxlsxio_read.a(xlsxio_read.c.o)
   "_unzLocateFile", referenced from:
       _XML_Char_openzip in libxlsxio_read.a(xlsxio_read.c.o)
   "_unzOpen", referenced from:
       _xlsxioread_open in libxlsxio_read.a(xlsxio_read.c.o)
   "_unzOpen2", referenced from:
       _xlsxioread_open_filehandle in 
libxlsxio_read.a(xlsxio_read.c.o)
       _xlsxioread_open_memory in libxlsxio_read.a(xlsxio_read.c.o)
   "_unzOpenCurrentFile", referenced from:
       _XML_Char_openzip in libxlsxio_read.a(xlsxio_read.c.o)
   "_unzReadCurrentFile", referenced from:
       _expat_process_zip_file in libxlsxio_read.a(xlsxio_read.c.o)
       _expat_process_zip_file_resume in 
libxlsxio_read.a(xlsxio_read.c.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to 
see invocation)
Error: linker exited with status 1
```
 From the first line of the error message, I gather I'm using the 
wrong minizip but I'm not sure how or why. What does **"building 
for macOS-x86_64 but attempting to link with file built for 
macOS-x86_64"** even mean?

Thanks,
confuzzled!!!


More information about the Digitalmars-d-learn mailing list