Recent

Author Topic: Cannot compile simple example with libcurl on MacOS with M1 cpu  (Read 1499 times)

ydd

  • Jr. Member
  • **
  • Posts: 50
project file:

Code: Pascal  [Select][+][-]
  1. program teststream;
  2. uses libcurl;
  3. var hCurl: pCurl;
  4. begin
  5.   hCurl := curl_easy_init;
  6. end.

compile log:
Quote
Project checks, Hints: 1
Note: passing compiler option -M twice with different values
Hint: (11030) Start of reading config file /Users/yd/Lazarus/v1.8.2n/fpc/bin/aarch64-darwin/fpc.cfg
Hint: (11031) End of reading config file /Users/yd/Lazarus/v1.8.2n/fpc/bin/aarch64-darwin/fpc.cfg
Free Pascal Compiler version 3.3.1-r49155 [2021/04/09] for aarch64
Copyright (c) 1993-2021 by Florian Klaempfl and others
(1002) Target OS: Darwin for AArch64
(3104) Compiling teststream.pp
/Volumes/Projects/Tests/Lazarus/libcurl/teststream.pp(43,5) Note: (5027) Local variable "hCurl" is assigned but never used
(9001) Assembling (pipe) /Volumes/Projects/Tests/Lazarus/libcurl/lib/aarch64-darwin/teststream.s
(9015) Linking /Volumes/Projects/Tests/Lazarus/libcurl/teststream
Undefined symbols for architecture arm64:
  "_curl_easy_init", referenced from:
      _PASCALMAIN in teststream.o
ld: symbol(s) not found for architecture arm64
Error: (9013) Error while linking
Fatal: (10026) There were 1 errors compiling module, stopping
Fatal: (1018) Compilation aborted
Error: /Users/yd/Lazarus/v1.8.2n/fpc/bin/aarch64-darwin/ppca64 returned an error exitcode

I installed curl using brew. I found that libcurl exists under: /opt/homebrew/Cellar/curl/7.76.1/lib
below is content of this dir:

Quote
┌<─ /opt/homebrew/Cellar/curl/7.76.1/lib ────────────────────────────────────────────.[^]>┐
│.n                              Name                                │ Size  │Modify time │
│/..                                                                 │UP--DIR│May  6 04:59│
│/pkgconfig                                                          │     96│May  6 04:59│
│ libcurl.4.dylib                                                    │ 596528│May  6 04:59│
│ libcurl.a                                                          │ 955824│Apr 14 08:58│
│@libcurl.dylib                                                      │     15│Apr 14 08:58│


question - how to make it to compile?
I can compile it on Windows & Linux.

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 884
Re: Cannot compile simple example with libcurl on MacOS with M1 cpu
« Reply #1 on: May 06, 2021, 08:21:24 pm »
Have you added that directory to the linker's library search path? (-Fl/opt/homebrew/Cellar/curl/7.76.1/lib) That directory is not a default directory in which the linker looks for libraries.

ydd

  • Jr. Member
  • **
  • Posts: 50
Re: Cannot compile simple example with libcurl on MacOS with M1 cpu
« Reply #2 on: May 06, 2021, 09:35:07 pm »
Have you added that directory to the linker's library search path? (-Fl/opt/homebrew/Cellar/curl/7.76.1/lib)

configured as you advised - same error

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 884
Re: Cannot compile simple example with libcurl on MacOS with M1 cpu
« Reply #3 on: May 06, 2021, 09:47:20 pm »
Looking at the source of that unit, it's missing a {$linklib curl} directive. I wonder why it was enabled for Darwin, since it was obviously never tested there.

(You can add that line to your program, it doesn't have to be in the unit itself)
« Last Edit: May 06, 2021, 10:03:25 pm by Jonas Maebe »

ydd

  • Jr. Member
  • **
  • Posts: 50
Re: Cannot compile simple example with libcurl on MacOS with M1 cpu
« Reply #4 on: May 06, 2021, 10:13:21 pm »
Looking at the source of that unit, it's missing a {$linklib curl} directive. I wonder why it was enabled for Darwin, since it was obviously never tested there.
(You can add that line to your program, it doesn't have to be in the unit itself)

added, got big number of other errors - see attached file

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 884
Re: Cannot compile simple example with libcurl on MacOS with M1 cpu
« Reply #5 on: May 06, 2021, 10:29:27 pm »
Looks like the compiler is selecting the static rather than the dynamic library to link against, not sure why (in that case you have to manually specify all of the dependent libraries to link against as well). Did you use {$linklib libcurl.a} perhaps? Try {$linklib libcurl.dylib} instead.

ydd

  • Jr. Member
  • **
  • Posts: 50
Re: Cannot compile simple example with libcurl on MacOS with M1 cpu
« Reply #6 on: May 06, 2021, 10:44:44 pm »
Looks like the compiler is selecting the static rather than the dynamic library to link against, not sure why (in that case you have to manually specify all of the dependent libraries to link against as well). Did you use {$linklib libcurl.a} perhaps? Try {$linklib libcurl.dylib} instead.

look like it does not matter - errors are same for "{$linklib x}" with: curl, libcurl, libcurl.a, libcurl.dylib

but magically it compiled for: {$linklib libcurl.4}

need to test

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 884
Re: Cannot compile simple example with libcurl on MacOS with M1 cpu
« Reply #7 on: May 06, 2021, 10:51:05 pm »
Well, there's only a libcurl.4.dylib in that directory, no libcurl.4.a, so that's "normal". Still strange it picked the static library in the other cases, as it really should default to dynamic.

ydd

  • Jr. Member
  • **
  • Posts: 50
Re: Cannot compile simple example with libcurl on MacOS with M1 cpu
« Reply #8 on: May 06, 2021, 11:42:32 pm »
Looking at the source of that unit, it's missing a {$linklib curl} directive. I wonder why it was enabled for Darwin, since it was obviously never tested there.

thank you for your help - I already spend 2 evenings trying to compile

does it mean that unit "libcurl" - should be fixed?

 

TinyPortal © 2005-2018