Re: Linking to Dynamic Library on Mac OS X
On Friday, 15 May 2015 at 19:49:30 UTC, John Colvin wrote: On Friday, 15 May 2015 at 19:39:53 UTC, TJB wrote: Off the top of my head: does adding -L-L$(pwd) help? This is what I get: $ dmd main.d -L-L$(pwd) -lhello Error: unrecognized switch '-lhello' Sorry if this is completely elementary and I am being quite dumb. Thanks, TJB should be $ dmd main.d -L-L$(pwd) -L-lhello This works perfectly. A big thanks!
Re: Linking to Dynamic Library on Mac OS X
Off the top of my head: does adding -L-L$(pwd) help? This is what I get: $ dmd main.d -L-L$(pwd) -lhello Error: unrecognized switch '-lhello' Sorry if this is completely elementary and I am being quite dumb. Thanks, TJB
Linking to Dynamic Library on Mac OS X
I have built a toy dynamic shared library on Mac OS X (in C), and I have verified that it works from C. Now I would like to call it from D. So I have created the following interface file: $ cat hello.di extern (C): void printHelloWorld(); which I try to compile and run. But I get the following error: $ dmd main.d -L-lhello ld: library not found for -lhello clang: error: linker command failed with exit code 1 (use -v to see invocation) --- errorlevel 1 I gather that mac os x doesn't know where to find libhello.dylib (it is in the current directory). So how do I pass that information? Thanks! TJB
Binding to C
I'm sure this question has been asked a thousand times. I've even asked similar questions in the past (I've been away for quite a while). But all of the tutorials that I have found assume quite a lot and leave a lot to be inferred. Is there a simple step by step tutorial demonstrating how to call C code from D? With the separate file contents and names and compilation instructions? Thanks, TJB
Re: CSV Data to Binary File
Thanks Marc. Not sure what to do here. I need to the binary data to be exactly the number of bytes as specified by the struct. How to handle the conversion from string to char[]? TJB (You forgot to include the error. For other readers: It fails to compile with "template std.conv.toImpl cannot deduce function from argument types !(char[4])(string)" and similar error messages.) This is caused by the two `char` arrays. `std.conv.to` cannot convert strings to fixed-size char arrays, probably because it's not clear what should happen if the input string is too long or too short. Would it be a good idea to support this? As a workaround, you could declare a second struct with the same members, but `ex` and `mmid` as strings, read your data into these, and assign it to the first structure: import std.algorithm; import std.csv; import stdio = std.stdio; import std.stream; align(1) struct QuotesBinDummy { int qtim; int bid; int ofr; int bidsiz; int ofrsiz; short mode; string ex; string mmid; } align(1) struct QuotesBin { int qtim; int bid; int ofr; int bidsiz; int ofrsiz; short mode; char[1] ex; char[4] mmid; } void main() { string infile = "temp.csv"; string outfile = "temp.bin"; Stream fin = new BufferedFile(infile); Stream fout = new BufferedFile(outfile, FileMode.Out); foreach(ulong n, char[] line; fin) { auto temp = csvReader!QuotesBinDummy(line).front; QuotesBin record; record.tupleof = temp.tupleof; fout.writeExact(&record, QuotesBin.sizeof); } fin.close(); fout.close(); } The line "record.tupleof = temp.tupleof;" will however fail with your example data, because the `ex` field includes a space in the CSV, and the last field is empty, but needs to be 4 chars long.
CSV Data to Binary File
I am trying to read data in from a csv file into a struct, and then turn around and write that data to binary format. Here is my code: import std.algorithm; import std.csv; import stdio = std.stdio; import std.stream; align(1) struct QuotesBin { int qtim;9 int bid; int ofr; int bidsiz; int ofrsiz; short mode; char[1] ex; char[4] mmid; } void main() { string infile = "temp.csv"; string outfile = "temp.bin"; Stream fin = new BufferedFile(infile); Stream fout = new BufferedFile(outfile, FileMode.Out); foreach(ulong n, char[] line; fin) { auto record = csvReader!QuotesBin(line).front; fout.writeExact(&record, QuotesBin.sizeof); } fin.close(); fout.close(); } Here is a snippet of my csv data: 34220, 37, 371200, 1, 1, 12, N, 34220, 369000, 372500, 1, 11, 12, P, 34220, 37, 371200, 1, 2, 12, N, 34220, 37, 371100, 1, 33, 12, N, 34220, 369400, 371100, 6, 3, 12, P, 34220, 37, 371200, 1, 2, 12, N, 34220, 369300, 371200, 9, 2, 12, N, 34220, 369300, 371200, 5, 2, 12, N, 34220, 368900, 371200, 13, 2, 12, N, 34220, 368900, 371100, 13, 1, 12, N, For some reason this fails miserably. Can anyone help me out as to why? What do I need to do differently? Thanks, TJB
Re: CSV Data to Binary File
On Thursday, 7 August 2014 at 15:11:48 UTC, TJB wrote: I am trying to read data in from a csv file into a struct, and then turn around and write that data to binary format. Here is my code: import std.algorithm; import std.csv; import stdio = std.stdio; import std.stream; align(1) struct QuotesBin { int qtim;9 int bid; int ofr; int bidsiz; int ofrsiz; short mode; char[1] ex; char[4] mmid; } void main() { string infile = "temp.csv"; string outfile = "temp.bin"; Stream fin = new BufferedFile(infile); Stream fout = new BufferedFile(outfile, FileMode.Out); foreach(ulong n, char[] line; fin) { auto record = csvReader!QuotesBin(line).front; fout.writeExact(&record, QuotesBin.sizeof); } fin.close(); fout.close(); } Here is a snippet of my csv data: 34220, 37, 371200, 1, 1, 12, N, 34220, 369000, 372500, 1, 11, 12, P, 34220, 37, 371200, 1, 2, 12, N, 34220, 37, 371100, 1, 33, 12, N, 34220, 369400, 371100, 6, 3, 12, P, 34220, 37, 371200, 1, 2, 12, N, 34220, 369300, 371200, 9, 2, 12, N, 34220, 369300, 371200, 5, 2, 12, N, 34220, 368900, 371200, 13, 2, 12, N, 34220, 368900, 371100, 13, 1, 12, N, For some reason this fails miserably. Can anyone help me out as to why? What do I need to do differently? Thanks, TJB Some of the code got messed up when I pasted. Should be: align(1) struct QuotesBin { int qtim; int bid; int ofr; int bidsiz; int ofrsiz; short mode; char[1] ex; char[4] mmid; } Thanks!
Re: Max/Min values in an associative array
Justin, That's it! Perfect - thanks!! TJB Do you just need the min and max values or do you also need the keys of those values? If the former, here's a paste: http://dpaste.dzfl.pl/0bbf31278a25
Max/Min values in an associative array
I am trying to find the max and min values in an associative array. Say I have: double[char] bids; bid['A'] = 37.50; bid['B'] = 38.11; bid['C'] = 36.12; How can I find the max and min values. I am thinking that I need to use max and min functions from std.algorithm, but not sure how to. Thanks! TJB
Re: Command Line Application in D
This is exactly what I was thinking. Thanks so much for your help! TJB Just a little something I made for you. Untested of course. But takes an argument from cli, which is a glob. Foreach file under current working directory, if its a file write out processing. (I gave std.stdio an alias because std.file and std.stdio conflict for some symbols) import std.file; import stdio = std.stdio; void main(string[] args) { if (args.length == 2) { foreach(entry; dirEntries(".", args[1], SpanMode.Depth)) { if (isDir(entry.name)) { } else if (isFile(entry.name)) { stdio.writeln("Processing " ~ entry.name); } } } else { stdio.writeln("Arguments: "); } }
Re: Command Line Application in D
On Monday, 4 August 2014 at 21:58:09 UTC, maarten van damme via Digitalmars-d-learn wrote: I am a little bit confused as to what you want. There is a command line example at dlang.org, and there exists a program (rdmd) that compiles several D files and runs them. http://dlang.org/rdmd.html Sorry. I wasn't very clear. Say I want to find all of the files that have a certain extension within a directory and process them somehow at the command line. How could I do that?
Command Line Application in D
I am trying to build some simple command line applications that I have written in python as a way to learn D. Can you give some examples for me? For instance, I think I remember once seeing somewhere in the documentation an example that took several D files and compiled them all by running some kind of system command. I much appreciate your help! TJB
Creating Libraries Callable from C
Is it possible to write a library that is callable from C without the enduser even knowing it was written in D? That is, can a C programmer use the library as though it were written in C straightforwardly? Or for that matter, by an enduser programming in Python or Lua where the library is being exposed through those languages' C API? I'm sure this is a widely discussed and well understood topic, but I am a newbie (and have no formal training in CS) and don't know where to look for documentation. A little baby tutorial would be super helpful and well received by this newbie. Thanks so much! TJB