简体   繁体   中英

How to create .dll or .lib from multiple c source and header files in visual studio?

I have C source files and header files from the first version(1.0) of Sundials numerical solver.

https://computing.llnl.gov/projects/sundials

In the makefile information for IDA solver, it looks like this.

# File Makefile.idas  Version of 16 December 1999

# Makefile for the serial version of the IDA package

# Notes on machine and environment dependencies:
#
# (1) Files from the IDA solver are accessed as follows:
#     (a) All IDA header files needed are assumed to be in the
#         directory given by IDAINC below.
#     (b) The IDA library file is given by IDALIB below.
#
# (2) The C compiler is given by CC below.
#
# Change these variables as needed for other environments.


IDAINC = ../include
IDALIB = ../lib/libidas.a

CC = cc

# Source files:

CODES = ida.c llnlmath.c idaspgmr.c spgmr.c iterativ.c idadense.c dense.c \
        idaband.c band.c nvector.c

# Object files:

OBJS =  ida.o llnlmath.o idaspgmr.o spgmr.o iterativ.o idadense.o dense.o \
        idaband.o band.o nvector.o


# Command sequence:
# Note that the proper versions of the files nvector.c and nvector.h are
# copied into the proper directories for the compile, then removed.

all:
    cp ./serial/nvector.c nvector.c
    cp $(IDAINC)/serial/nvector.h $(IDAINC)/nvector.h
    $(CC) -c $(CODES) -I$(IDAINC)
    ar rcv $(IDALIB) $(OBJS)
    rm -f *.o
    rm $(IDAINC)/nvector.h
    rm ./nvector.c

To me, the unix command simply compiles all the source codes and then link all the objective files into library file *.a in unix.

I would like to do the same thing in Windows 10 and visual studio (2019) or any other window C software to make a static library, *.lib. Can you help me how to do this?

Thanks,

"I would like to do the same thing in Windows 10 and visual studio (2019)..."

Here are example steps using Visual Studio 2019:

Note, because Visual Studios is by definition an IDE, it removes much of the the responsibility from the developer to know as much about make-files and command line-compile instructions. These things are done within the Visual Studios application via menus and buttons on a GUI.

  • On the menu bar, choose File > New > Project to open the Create a New Project dialog box.

  • At the top of the dialog, set Language to C++ [or C] , set Platform to Windows, and set Project type to Library.

  • From the filtered list of project types, select [Console App] , then choose Next.

  • In the Configure your new project page, enter some [Name] in the Project name box to specify a name for the project. Enter [StaticNameLib] in the Solution name box. Choose the Create button to open the Windows Desktop Project dialog.

  • In the Windows Desktop Project dialog, under Application type, select Static Library (.lib).

  • Under Additional options, uncheck the Precompiled header check box if it's checked. Check the Empty project box.

  • Choose OK to create the project.

Note: Content within italicized square brackets ( [...] ) is mine. See link below for original.

link below

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM