Using libraries

Started by
13 comments, last by DeadXorAlive 17 years, 8 months ago
I'm getting very confused about how to use others' libraries. Most libraries, it seems, are aimed at Unix users. They ship with files that have no extensions, and have LF line endings instead of CRLF. There seems to be some sort of a standard process about how to install and use these libraries, but I don't know it. Will someone be so kind as to explain or provide a link about how to intall and use libraries? I've turned many libraries down simply because I don't know how to install them. I understand the README file can be opened with WordPad, even though it does not have an extension. WordPad also accomodates for the non-native line endings. The worst thing is that the README file assumes the user is familiar, and possible even sick of, the explanation for how to install the library. An example:
Quote: 2. Installation ------------------------------------------------------------------------------- The usual configure [--disable-static] [--enable-debug] make make check make install should do the trick. You can skip the "make check" parts if you do not want to run the regression tests.
To be more specific, I've noticed libraries usually ship with a file called CONFIGURE, another called MAKEFILE, and perhaps another called INSTALL. The extensions are usually missing, but sometimes they include .in, .bat, .bak, and various others. Since most docs lack the explanation for what to do with these, can someone provide a quick one for me? --- And here's a much more specific case. I'm trying to install the OpenSSL library. Here are the instructions for installing on Win32 using Visual C++:
Quote: Visual C++ ---------- If you want to compile in the assembly language routines with Visual C++ then you will need an assembler. This is worth doing because it will result in faster code: for example it will typically result in a 2 times speedup in the RSA routines. Currently the following assemblers are supported: * Microsoft MASM (aka "ml") * Free Netwide Assembler NASM. MASM is distributed with most versions of VC++. For the versions where it is not included in VC++, it is also distributed with some Microsoft DDKs, for example the Windows NT 4.0 DDK and the Windows 98 DDK. If you do not have either of these DDKs then you can just download the binaries for the Windows 98 DDK and extract and rename the two files XXXXXml.exe and XXXXXml.err, to ml.exe and ml.err and install somewhere on your PATH. Both DDKs can be downloaded from the Microsoft developers site www.msdn.com. NASM is freely available. Version 0.98 was used during testing: other versions may also work. It is available from many places, see for example: http://www.kernel.org/pub/software/devel/nasm/binaries/win32/ The NASM binary nasmw.exe needs to be installed anywhere on your PATH. Firstly you should run Configure: > perl Configure VC-WIN32 --prefix=c:/some/openssl/dir Where the prefix argument specifies where OpenSSL will be installed to. Next you need to build the Makefiles and optionally the assembly language files: - If you are using MASM then run: > ms\do_masm - If you are using NASM then run: > ms\do_nasm - If you don't want to use the assembly language files at all then run: > ms\do_ms If you get errors about things not having numbers assigned then check the troubleshooting section: you probably won't be able to compile it as it stands. Then from the VC++ environment at a prompt do: > nmake -f ms\ntdll.mak If all is well it should compile and you will have some DLLs and executables in out32dll. If you want to try the tests then do: > nmake -f ms\ntdll.mak test To install OpenSSL to the specified location do: > nmake -f ms\ntdll.mak install
I've followed those instructions blindly up to a point. I'm a bit lost with this step: Then from the VC++ environment at a prompt do: > nmake -f ms\ntdll.mak So, where do I run this command? In Visual Studio, I am aware that there is a window called the "command window", which looks a lot like a command prompt. But there is no such instruction there as "nmake". It's an unrecognized command. Neither did I find any mention of "nmake" in the directory where I installed the library (I searched the directory, but it turned up nothing). So it is neither a command recognized by Visual Studio, nor any sort of an executable file in the library directory. What do I do? I will greatly appreciate any help you guys can offer on this.
.:<<-v0d[KA]->>:.
Advertisement
Well I too find building libraries often quite annoying, it can be a complicated process especially for windows users like me not used to all the *nix conventions. (But what's nice about them is they have conventions at all)
To begin with I would recommend The correct C++ tutorial, part 5 goes about some details of building libraries. (warning: painful but you'll learn some things).


Quote:So, where do I run this command? In Visual Studio, I am aware that there is a window called the "command window", which looks a lot like a command prompt. But there is no such instruction there as "nmake". It's an unrecognized command. Neither did I find any mention of "nmake" in the directory where I installed the library (I searched the directory, but it turned up nothing). So it is neither a command recognized by Visual Studio, nor any sort of an executable file in the library directory.


From this text it is not clear to me exactly what you did, and what you didn't understand. You can get a console window with a 'prompt' by running cmd.exe. (start menu->run, enter 'cmd') From there you'll have to call nmake, which is a program that builds programs or libraries using so called makefiles, which contain instructions and information on how a library should be build. But, from a prompt you'll have to be able to locate nmake and other neccesary directories, it should be in the 'path'. (type path to see a list of current directories in the search path). I'm not a regular VC user, but iirc there is a bat file called vcvars32.bat that will set up locations of needed paths and other needed variables if neccesary. (btw, to see these variables hit the windows key and break, and look under advanced->environment variables).

So the steps to be taken will be something like: open a prompt (cmd.exe), find vcvars32.bat and execute it, navigate to the library directory containing a makefile and execute nmake from there.

Well ask more questions if you don't understand something. Hopefully somebody will come along explaining things more clear than I do.
It all depends on inteded use, from the looks of things you are a Visual Studio user. What you want is a windows library, so you'll have to use Visual Studio to compile the library. The easiest way to do this is look for a visual studio project file, open and compile. If one doesn't exist you'll have to create a static or dynamic lib and import the library files from the extracted folder. Then compile.

If you are using a unix compiler on windows to create a library for windows (.a extention) you'll have to download Cygwin and when the installing specify you want make support. From there type cd "directory" and follow the steps they suggest.

If you're still having trouble I'd be willing to help you out a little to compile.
Quote:Original post by DeadXorAlive
From there you'll have to call nmake, which is a program that builds programs or libraries


Ah, thank you, I thought nmake was some sort of a command, but it turns out it's a program. It looks like it was missing, but from googling, I actually found a download link by Microsoft for that program.

So I did that part of the installation instructions for OpenSSL, but I received an error in the command prompt:
"'cl' is not recognized as an internal or external command,
operable program or batch file.
NMAKE : fatal error U1077: 'C:\WINDOWS\system32\cmd.exe' : return code '0x1'
Stop."

So I googled what may have caused this. And at that, I spent a lot of time, finding errors which were not quite related.

In the end, quite ironically, I found this:
Quote:
The Win32 OpenSSL Installation Project is dedicated to providing a simple installation of OpenSSL. It is easy to set up and easy to use through the simple, effective installer. No need to compile anything or jump through any hoops, just click a few times and it is installed, leaving you to doing real work. Download it today!


[grin]

Well anyways, thanks for the help, and thanks for the link. This is not the last library I will be installing today (OpenSSL is merely a prerequisite for the real library libcurl). If the installation for the other libraries is anything like this one, I'm sure I'll be back with more questions.
.:<<-v0d[KA]->>:.
Can anyone explain this to me?

Quote:
To figure out if an installed libcurl has been built with SSL support enabled, use 'curl-config' like this:

$ curl-config --feature


The "curl-config" that they speak of is a file without an extension. Their instructions, and also the fact that the file is in the "bin" directory, are leading me to believe that it's an executable program.

However, if I open the file in Wordpad, it looks like this, which clearly can't be an executable:

#! /bin/sh#***************************************************************************#                                  _   _ ____  _#  Project                     ___| | | |  _ \| |#                             / __| | | | |_) | |#                            | (__| |_| |  _ <| |___#                             \___|\___/|_| \_\_____|## Copyright (C) 2001 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.## This software is licensed as described in the file COPYING, which# you should have received as part of this distribution. The terms# are also available at http://curl.haxx.se/docs/copyright.html.## You may opt to use, copy, modify, merge, publish, distribute and/or sell# copies of the Software, and permit persons to whom the Software is# furnished to do so, under the terms of the COPYING file.## This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY# KIND, either express or implied.## $Id: curl-config.in,v 1.25 2006-05-02 22:48:22 bagder Exp $############################################################################# The idea to this kind of setup info script was stolen from numerous# other packages, such as neon, libxml and gnome.#prefix=/usr/localexec_prefix=${prefix}includedir=${prefix}/includeusage(){    cat <<EOFUsage: curl-config [OPTION]Available values for OPTION include:  --ca        ca bundle install path  --cc        compiler  --cflags    pre-processor and compiler flags  --checkfor [version] check for (lib)curl of the specified version  --features  newline separated list of enabled features  --protocols newline separated list of enabled protocols  --help      display this help and exit  --libs      library linking information  --prefix    curl install prefix  --version   output version information  --vernum    output the version information as a number (hexadecimal)EOF    exit $1}if test $# -eq 0; then    usage 1fiwhile test $# -gt 0; do    case "$1" in    # this deals with options in the style    # --option=value and extracts the value part    # [not currently used]    -*=*) value=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;    *) value= ;;    esac    case "$1" in    --ca)	echo ""/usr/local/share/curl/curl-ca-bundle.crt""	;;    --cc)	echo "i586-mingw32msvc-gcc"	;;    --prefix)	echo "$prefix"	;;    --feature|--features)	if test "1" = "1"; then          echo "SSL"          NTLM=1 # OpenSSL implies NTLM        elif test -n ""; then          echo "SSL"        fi	if test "" = "1"; then          echo "KRB4"        fi	if test "" = "1"; then          echo "IPv6"        fi	if test "1" = "1"; then          echo "libz"        fi	if test "" = "1"; then          echo "AsynchDNS"        fi	if test "" = "1"; then          echo "IDN"        fi	if test "" = "1"; then          echo "SSPI"          NTLM=1        fi	if test "$NTLM" = "1"; then          echo "NTLM"        fi	;;    --protocols)	if test "" != "1"; then          echo "HTTP"	  if test "1" = "1"; then            echo "HTTPS"          fi        fi	if test "" != "1"; then          echo "FTP"	  if test "1" = "1"; then            echo "FTPS"          fi        fi	if test "" != "1"; then          echo "FILE"        fi	if test "" != "1"; then          echo "TELNET"        fi	if test "" != "1"; then          echo "LDAP"        fi	if test "" != "1"; then          echo "DICT"        fi	if test "" != "1"; then          echo "TFTP"        fi	;;    --version)	echo libcurl 7.15.4	exit 0	;;    --checkfor)        checkfor=$2        cmajor=`echo $checkfor | cut -d. -f1`        cminor=`echo $checkfor | cut -d. -f2`        # when extracting the patch part we strip off everything after a	# dash as that's used for things like version 1.2.3-CVS	cpatch=`echo $checkfor | cut -d. -f3 | cut -d- -f1`        checknum=`echo "$cmajor*256*256 + $cminor*256 + ${cpatch:-0}" | bc`        numuppercase=`echo 070f04 | tr 'a-f' 'A-F'`        nownum=`echo "obase=10; ibase=16; $numuppercase" | bc`	if test "$nownum" -ge "$checknum"; then	  # silent success	  exit 0	else	  echo "requested version $checkfor is newer than existing 7.15.4"	  exit 1	fi	;;    --vernum)	echo 070f04	exit 0	;;    --help)	usage 0	;;    --cflags)       	if test "X${prefix}/include" = "X/usr/include"; then          echo ""        else          echo "-I${prefix}/include"        fi       	;;    --libs)       	echo -L${exec_prefix}/lib -lcurl -L/home/dast/src/win32 -lssl -lcrypto -lgdi32 -lwinmm -lws2_32  -lz -lws2_32       	;;    *)        echo "unknown option: $1"	usage 1	;;    esac    shiftdoneexit 0


Can anyone conclude from what's given here what kind of a file this is? And how/where can I use the command they gave in the instructions, the "$ curl-config --feature"?

Thanks again.
.:<<-v0d[KA]->>:.
Quote:Original post by v0dKA
Quote:Original post by DeadXorAlive
From there you'll have to call nmake, which is a program that builds programs or libraries


Ah, thank you, I thought nmake was some sort of a command, but it turns out it's a program. It looks like it was missing, but from googling, I actually found a download link by Microsoft for that program.

So I did that part of the installation instructions for OpenSSL, but I received an error in the command prompt:
"'cl' is not recognized as an internal or external command,
operable program or batch file.
NMAKE : fatal error U1077: 'C:\WINDOWS\system32\cmd.exe' : return code '0x1'
Stop."

So I googled what may have caused this. And at that, I spent a lot of time, finding errors which were not quite related.

In the end, quite ironically, I found this:
Quote:
The Win32 OpenSSL Installation Project is dedicated to providing a simple installation of OpenSSL. It is easy to set up and easy to use through the simple, effective installer. No need to compile anything or jump through any hoops, just click a few times and it is installed, leaving you to doing real work. Download it today!


[grin]

Well anyways, thanks for the help, and thanks for the link. This is not the last library I will be installing today (OpenSSL is merely a prerequisite for the real library libcurl). If the installation for the other libraries is anything like this one, I'm sure I'll be back with more questions.


LOL, that's good. Nmake is an part of visual studio. I have visual studio express, it's under VC\bin. I hope you succeed in building.

It would be a nice addition to the big pile of knowledge on the internets if someone took up the perhaps boring task of writing a comprehensive and clear guide on all the building voodoo. If it already exists (couldn't find it) and someone has a link please post.
Quote:Original post by v0dKA
Can anyone conclude from what's given here what kind of a file this is? And how/where can I use the command they gave in the instructions, the "$ curl-config --feature"?

Its a "shell script" -- equivalent to a DOS "batch file". The line
   #! /bin/sh 
tells the OS which shell (command line environment) to use to execute it. In this case, the Bourne shell is used (because /bin/sh is its executable file).

You are right that a lot of software is specific to Unix or Linux. Many times but not always, there is an equivalent for Windows. You can also run Unix commands and shell scripts using a Unix emulator such as Cygwin or MinGW.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
I'll guess it's a script. the '$' symbol indicates a *nix prompt. You can use cygwin or msys to emulate this linux environment and execute it.
Quote:Original post by DeadXorAlive
I'll guess it's a script. the '$' symbol indicates a *nix prompt. You can use cygwin or msys to emulate this linux environment and execute it.


Yes it is a shell script, v0dKa, is there a reason you want to compile the library?
it seems a lot easier to download the development binaries at the bottom of this list and extract them into the Platform SDK directory.

Hint: Always look for Windows Binaries before downloading the source package.
Quote:Original post by Kwizatz
Quote:Original post by DeadXorAlive
I'll guess it's a script. the '$' symbol indicates a *nix prompt. You can use cygwin or msys to emulate this linux environment and execute it.


Yes it is a shell script, v0dKa, is there a reason you want to compile the library?
it seems a lot easier to download the development binaries at the bottom of this list and extract them into the Platform SDK directory.

Hint: Always look for Windows Binaries before downloading the source package.


This was a Windows package. And in fact, the library already came precompiled.

But there is a problem:

In the lib folder, where the output library was supposed to already be, there are four libraries, but neither of them with the classic .lib extension. Instead, the files read like this: libcurl-3.dll, libcurl.a, libcurl.dll.a, and libcurl.la.

Thus, I had to go to the documentation to see what to use. But the documentation says:
Quote:
When having compiled the program, you need to link your object files to create a single executable. For that to succeed, you need to link with libcurl and possibly also with other libraries that libcurl itself depends on. Like the OpenSSL libraries, but even some standard OS libraries may be needed on the command line. To figure out which flags to use, once again the 'curl-config' tool comes to the rescue:

$ curl-config --libs


So I'm installing Cygwin now in order to be able to run the Curl-config script. I hope I won't have to use it for future libraries [grin].

In any case, any day now, I'll be installing Linux on my old computer. Learning how to use it may take another decade, but hopefully, I'll be more aware of the *nix conventions.
.:<<-v0d[KA]->>:.

This topic is closed to new replies.

Advertisement