Last active
June 19, 2020 16:15
-
-
Save gnowzil/4bfc0b6c0ec725d0188bded45c885162 to your computer and use it in GitHub Desktop.
Makefile for SNOPT/AMPL from library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#----------------------------------------------------------------------- | |
# Makefile to create SNOPT AMPL executable from libsnopt7.a | |
# | |
# Assumes you have downloaded solvers.tgz and snopt.tgz and | |
# that you ran "./configurehere; make" in the solvers | |
# directory to build amplsolver.a | |
#----------------------------------------------------------------------- | |
SNOPT_LIB = /path/to/libsnopt7.a | |
AMPL_SOLVERS_DIR = solvers | |
SNOPT_AMPL_DIR = snopt | |
AMPL_INCLUDE = $(AMPL_SOLVERS_DIR) | |
#----------------------------------------------------------------------- | |
all: snopt_ampl | |
clean: clean_ampl | |
snopt_ampl: $(SNOPT_AMPL_DIR)/snopt.o | |
$(FC) $(FCFLAGS) -o $@ $(SNOPT_AMPL_DIR)/snopt.o $(AMPL_SOLVERS_DIR)/amplsolver.a $(SNOPT_LIB) -ldl | |
$(SNOPT_AMPL_DIR)/%.o: $(SNOPT_AMPL_DIR)/%.c | |
$(CC) $(CFLAGS) -I$(AMPL_INCLUDE) -c $< -o $@ | |
#----------------------------------------------------------------------- | |
clean_ampl: | |
$(CLEAN) rm -f $(SNOPT_AMPL_DIR)/snopt.o | |
#----------------------------------------------------------------------- | |
.PHONY: clean_ampl |
-
Download solvers.tgz and snopt.tgz from netlib, uncompress. Should create directories 'solvers' and 'snopt'.
-
Create a file
fmain.c
inside the solvers directory with the code below and add it to the list of files built by ASL. (look for "a = ..." inside makefile in the solvers dir). (This is also documented in ASL's instructions in README.f77).
char **xargv;
extern void MAIN__(void);
int main(int argc, char **argv)
{
xargv = argv;
MAIN__();
return 0;
}
-
In solvers directory, run
./configurehere; make
. You should see amplsolver.a now. -
Copy
makefile_ampl
above. -
Modify
SNOPT_LIB
to point to the snopt7 library. If necessary, modify the other locations as well. By default, it assumes that the directories 'solvers' and 'snopt' are on the same level as the file.
SNOPT_LIB
should point to the libsnopt7.a fileAMPL_SOLVERS_DIR
should point to the 'solvers' directorySNOPT_AMPL_DIR
should point to the 'snopt' asl directory.
- Run makefile_ampl with the command
make -f makefile_ampl
. It should create the executable 'snopt_ampl'.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We also need to create a file
fmain.c
with the following in it:This file should be placed in the 'solvers' directory and makefile in solvers needs to be updated by adding 'fmain.c' to the list of files built (look for 'a = ...').