Is there a -Dmacro like option for D compilers?

2023-03-27 Thread Jeremy via Digitalmars-d-learn
Is there a way I can define a manifest constant from the compiler 
command-line, like the -Dmacro option for C compilers?


Re: std.net.curl.HTTP: can't download more than 3.6K

2023-03-19 Thread Jeremy via Digitalmars-d-learn
Nevermind, it was my fault. I fixed my problem by appending the 
received buffer to my data buffer instead of overwriting my data 
buffer each time.


Re: Difference between using `import` with/without the colon

2023-03-19 Thread Jeremy via Digitalmars-d-learn

On Sunday, 19 March 2023 at 08:47:32 UTC, Basile B. wrote:

On Sunday, 19 March 2023 at 07:20:17 UTC, Jeremy wrote:

[...]


The colon-form, aka "selective import" has for effect

1. to create a local alias so this can indeed speedup symbol 
lookups in the sense that search will succeed before looking in 
the scope of the imports.
2. to make non-selected symbols, i.e not listed in the colon 
right hand side, in the import not available.


Note that using both makes no sense, but I guess you did that 
to express more clearly what you meant.


Ah, that makes sense. Thank you!


Difference between using `import` with/without the colon

2023-03-19 Thread Jeremy via Digitalmars-d-learn
Hello, is there any difference at all between the following 
lines, as an example:


```d
import std.regex;
import std.regex : matchFirst;
```

What technical differences does it make (except for having the 
identifier available), using the colon?
Does it make any speed/optimization changes or am I better off 
just importing the whole module?


std.net.curl.HTTP: can't download more than 3.6K

2023-03-19 Thread Jeremy via Digitalmars-d-learn
Hello, I'm new to D and the `std.net.curl` library. I'm using the 
`HTTP` struct because I need to set headers for an API, and most 
of the time, I can only download 3.6 kilobytes at a time. Would 
this be a problem with the library not following redirects or 
something else? I'm not really sure what it could be, so could 
someone help me with this?


Re: #define-like behavior

2023-03-14 Thread Jeremy via Digitalmars-d-learn

On Tuesday, 14 March 2023 at 06:20:29 UTC, Mike Parker wrote:

On Tuesday, 14 March 2023 at 05:47:35 UTC, Jeremy wrote:

[...]


Manifest constants in D have a similar effect as #defined 
values, e.g.:


[...]


Thanks a lot!


#define-like behavior

2023-03-13 Thread Jeremy via Digitalmars-d-learn
Hi, in C and C++ you can use #define to substitute a value in 
place of an identifier while preprocessing. If you initialize a 
new string and don't change its value after that, will the 
compiler substitute the string identifier with its value, like 
#define in C, or will it make a string in memory and refer to 
that?


Re: Directly compiling a D program with other libraries

2023-03-13 Thread Jeremy via Digitalmars-d-learn
That's a linker error, meaning the missing symbol isn't 
available to link into the executable. You need to compile the 
source of all the libraries you use and make sure the resultant 
binaries are available for the linker to link into the 
executable.


The -I switch you've passed tells the compiler where to find 
imported modules. The compiler needs parse them to know which 
symbols are available for you to use when it's compiling your 
code. (The current working directory is the default anyway, so 
you don't need to pass `-I.` for that.)


By default, the compiler does not compile imported modules. If 
you add `-i` to the command line, then it will compile all of 
the modules you import (as long as they're in the `-I` path), 
excluding the DRuntime and Phobos modules. It will then also 
pass all of the compiled object files to the linker, so then 
your linker error should go away.




Using `-i` solved my problem, thank you very much!

However, when you choose not to use dub, you need to also 
ensure that you are accounting for any special compiler flags 
the libraries you use may require (for example, specific 
`-version` values). If they're configured to compile as static 
or shared libraries, it may be easier just to store the source 
for each of them outside of your project's source tree, use dub 
to build each of them, and then pass the compiled libraries to 
the compiler when you build your program. In that case, you 
wouldn't use `-i`. Just make sure that `-I` is correctly 
configured in that case.


Okay, thanks.


Directly compiling a D program with other libraries

2023-03-12 Thread Jeremy via Digitalmars-d-learn

Hello, I am new to this forum and to D.

I am trying to compile a basic D program with libraries 
(`requests` which requires `cachetools` and `automem`) without 
using dub. I have never used dub before, only a compiler.


The folders containing the libraries are in the same folder as 
main.d, the file I am trying to compile, and the command I am 
using to compile is `ldc2 -I. main.d`.


When I compile my program, I just get linker errors such as:
```
/usr/lib/gcc/x86_64-pc-linux-gnu/12/../../../../x86_64-pc-linux-gnu/bin/ld: 
main.o: in function `_Dmain':
main.d:(.text._Dmain+0x2f): undefined reference to 
`_D8requests10getContentFNcAyaZSQBd7streams__T6BufferThZQk'

```

Does anyone have any advice on how to solve my problem?