I am looking for some implementation of SPICE (electronic circuits simulator) written in C language which can be used as library.
I found some SPICE clone for Python and for Java, but not for C.
So far, I am using ngspice. It is very good clone of SPICE3, it is written in C, it has very good documentation. Is it possible to use it as library (so I can compile it into shared library and use it in my C project)? I compiled ngspice from source, but the result is CLI interface. Is there any option I can compile it into shared library?
But I am fine with any other SPICE clone.
ngspice now (mid-2013) now has an option to build as a shared library or dll to link into your app - it's documented in chapter 19 of the June 2013 manual (not the manual in the ngspice-25 release).
The 'Unix Way' would be to use the CLI program as is and use the 'system' standard library call to execute the binary (or fork/exec). Much less work than what you are trying to propose and with the amount that you are going to be calling the external application the overhead of doing the system call will be negligible.
Related
My goal is to use LAPACK with Emscripten. Emscripten is capable of transforming C code to JavaScript. But unfortunately, LAPACK 3.5.0 (http://www.netlib.org/lapack/) is only available in FORTRAN95.
The CLAPACK project (http://www.netlib.org/clapack/) is basically what I want: a C version of LAPACK. But this one is outdated; the latest is 3.2.1.
So my question now is: why is there no newer port of LAPACK to C? Are there any suggestion how to achieve my goal anyway?
Thanks in advance!
I managed to port LAPACKE, the LAPACK C-wrapper to javascript. Nevertheless I can't work with it, because the wrapper uses internal the FORTRAN routines. How would I embed these in emscripten?
E.g. the function LAPACKE_cgbcon uses LAPACKE_xerbla which is only available in FORTRAN. Why would I benefit from porting a wrapper?
The new version uses Fortran 95. There exist no automatic translation tool from it to C.
There is a new tool called fable available, but it also supports only a small subset of Fortran 90. They claimed to be able to translate part of LAPACK 3.2.1, but there are no news about full and more recent LAPACK.
Do you really need the code in C? Can't you just call it from C, possibly using an existing C wrapper?
For the official C API see http://www.netlib.org/lapack/#_standard_c_language_apis_for_lapack
I'm in the process of teaching myself C (coming from Java). I appreciate the language a lot, and one of the main reasons I am learning it is so that I can utilize the JNI feature built into Java to write native code when necessary. My question is mainly about the Windows API. Can I use the functions and features of the API using just C?
Will the Windows API be compatible with pure C code or does it contain classes and such that can only be utilized by C++ code?
Also, if I compiled a shared library on a Windows machine as (lib.sl NOT lib.dll), would it work on another machine (Mac/Linux)?
The Windows API (aka Win32 API) is a pure C library.
No you cannot use a Windows shared library on another non-Windows machine unless there is a software that supports Windows ABI - such as Wine or ReactOS.
Win32 API like others have pointed out is pure C. It means, once you get a hold of it, you will know everything about how the Operating system works. It is the same case usually with other operating systems as well. If you are after MFC/COM+ or Java wrappers, it is quite the opposite even if you can build great programs.
I would like to port a few applications that I use on Linux to Windows. In particular I have been working on wdiff. A program that compares the differences word by word of two files.
Currently I have been able to successfully compile the program on windows through Cygwin. However, I would like to run the program natively on Windows similar to the Project: UnixUtils.
How would I go about porting unix utilities on a windows environment?
My possible guess it to manually create the ./configure file so that I can create a proper makefile. Am I on the right track? Has anyone had experience porting GNU software to windows?
Update:
I've compiled it on Code::Blocks and I get two errors:
wdiff.c|226|error: `SIGPIPE'
undeclared (first use in this
function)
readpipe.c:71: undefined reference to `_pipe'
readpipe.c:74: undefined reference to `_fork
This is a linux signal that is not supported by windows... equvilancy?
wdiff.c|1198|error: `PRODUCT'
undeclared (first use in this
function)|
this is in the configure.in file... hardcode would probably be the fastest solution...
Outcome:
MSYS took care of the configure problems, however MinGW couldnt solve the posix issues. I attempt to utilize pthreads as recommended by mrjoltcola. However, after several hours I couldnt get it to compile nor link using the provided libraries. I think if this had worked it would have been the solution I was after.
Special mention to Michael Madsen for MSYS.
Yes. If you stick to the standard C library, and POSIX functions, most is available on Windows. You may just have to find the implementations. There are implementations of things that do not require Cywgin or MinGW (such as a pthreads package, etc.)
Also, there is a great book that is written in the style of W. Richard Steven's Advanced Proramming in the UNIX Environment, and the book is Windows System Programming, author Johnson Hart. He has a 4th edition. It focuses on System Programming, there is no GUI treatment whatsoever.
http://www.amazon.com/Windows-Programming-Addison-Wesley-Microsoft-Technology/dp/0321657748
It is the best book I know of for a UNIX programming moving to Windows.
You can have a look at MinGW (and MSYS), which are similar to cygwin, but gcc produce native Windows executables. However, since the Unix emulation is not as good as cygwin, you may have to adjust your code.
Always try to following standarts even when porting applications. POSIX compliant compilers exist on windows/Linux. You can try mingw. It has full toolchain required to build standart POSIX application (GNU Linux as well). Check out Dev-Cpp it eases the work.
MinGW is about the easiest way to get gcc and associated binary utilities (including gdb) on a Windows PC. It includes header files and import libraries so that you can call native Windows APIs. If you want more of an integrated IDE development environment you could download Microsoft's free Visual Studio Express C++.
Either way you'll likely have to convert some of the function calls to use Windows specific APIs (if you want a book I'd also recommend the Hart book mentioned in mrjoltcola's answer). For simple command line tools this conversion is usually not a huge deal, the big porting nightmares tend to involve tools with GUIs which have deep embedded dependencies on the GUI framework provided by the OS.
I am looking into making a C program which is divided into a Core and Extensions. These extensions should allow the program to be extended by adding new functions. so far I have found c-pluff a plugin framework which claims to do the same. if anybody has any other ideas or reference I can check out please let me know.
You're not mentioning a platform, and this is outside the support of the language itself.
For POSIX/Unix/Linux, look into dlopen() and friends.
In Windows, use LoadLibrary().
Basically, these will allow you to load code from a platform-specific file (.so and .dll, respectively), look up addresses to named symbols/functions in the loaded file, and access/run them.
I tried to limit myself to the low-level stuff, but if you want to have a wrapper for both of the above, look at glib's module API.
The traditional way on windows is with DLLs. But this kind of obselete. If you want users to actually extend your program (as opposed to your developer team releasing official plugins) you will want to embed a scripting language like Python or Lua, because they are easier to code in.
You can extend your core C/C++ program using some script language, for example - Lua
There are several C/C++ - Lua integration tools (toLua, toLua++, etc.)
Do you need to be able to add these extensions to the running program, or at least after the executable file is created? If you can re-link (or even re-compile) the program after having added an extension, perhaps simple callbacks would be enough?
If you're using Windows you could try using COM. It requires a lot of attention to detail, and is kind of painful to use from C, but it would allow you to build extension points with well-defined interfaces and an object-oriented structure.
In this usage case, extensions label themselves with a 'Component Category' defined by your app, hwich allows the Core to find and load them withough havng to know where their DLLs are. The extensions also implement interfaces that are specified using IDL and are consumed by the core.
This is old tech now, but it does work.
I'd hate to have to relearn C++ just for this! Any libraries/URLs would be great and yes, Google didn't help much here :-(
This is for an upcoming project in which my product (Java based) would provide support for Microsoft's Hyper-V virtualization platform. Unlike VMware, which provides a Web-service, the Hyper-V APIs are mere extensions of WMI. I'd prefer not to use commercial tools such as J-Integra for Java integration into COM/WMI and the few open source tools I found are way outdated.
I would rather use JNI with C than C++. Anybody know where I can find libraries et cetera for using C for WMI operations? In the same vein as Python clients can be used? (And yes, I know C is not an OOP language :D ).
Thanks in advance.
WMI is acessed via COM right?
While it is more verbose and more error-prone (it is easy to accidentally use different pointers for the vtable and the "this" parameter), you can also use COM from the C language.
You also could use C++ but treat it as "C with language extensions to make using COM easier".
The JNI interface itself is a derivative of COM and you will find those methods and the methods of the WMI interfaces much easier to use if you use enough C++ to treat interfaces as implemented by C++ classes.
The other thing that will be helpful is that you will be able to use the COM interface pointers and reference counting as a way to bind the lifecyle of the COM interface to the lifecycle of your JNI-implemented Java classes.
I used an approach like this to implement a Java bridge, via JNI, to some C Language interfaces on Windows. I hand-rolled COM interfaces and a .lib that is used in building the JNI DLL.
The difficult part, with WMI, is that you will want to use the standard COM APIs to Instantiate the COM objects, whereas I created my own custom "factory" code, since it was all a private implementation.
You can download a snapshot of my development tree for the ODMJNI 1.0 0.50beta Function-Complete Release. If you look at info.odma.odmjni100 in the development tree you'll see how the JNI DLL is built (using VC++ 2005 Express Edition) and Java 1.5. The OdmJniBind.java class consists of the static methods that are used in the Java classes to coordinate object lifecycles between Java Classes and COM Object interfaces. (the OdmNative peer section of the tree provides the implementation of the OdmNative100.lib that is used in compiling the odmjni100.dll that is used via JNI.
#z0ltan
You can write your code in C but you ll have to save the file as CPP. As someone had mentioned earlier, for DCOM support your file needs to be a CPP file.
#Umi
For Java Integration - compile your WMI code in C/CPP as a DLL (with proper JNI header files) and then you will have to load the DLL library file. Once this is done, you can access the WMI methods in DLL files just like calling a Java Method.