HI,
I have an error: undefined reference to EVP_CIPHER_CTX_init'. I have the encryption code in the header.cpp. In header.h i've initialized the method that i use for encryption. i've created an ar lib.a from header.cpp and header.h. i've added the -lcrypto but still when i run the test.cpp code where i've added in the header the header.h and i compile g++ test.cpp -o test -lib.a i have this error. where am i wrong?
the compilation code:
g++ -c -static -L -lb header.cpp -lcrypto -o lib.o
ar rcs lib.a lib.o
g++ test.cpp -o tst libr.a
in the header.h i did include all the libraries necesarry for the openssl/evp.h and so on. In test.cpp i've included header.h file.
Related
I am currently writing a small test application to explore statically linking libraries and accessing their symbols at runtime with Boost.DLL. I am attempting to compile a very simple static library and link it with a very simple application, using MinGW-w64, and am doing this with a Makefile and mingw32-make.
The following is the Makefile:
B_INCLUDE_PATH = -IC:/Unix/boost_1_78_0/
INCLUDE_PATH = -IC:/Unix/boost_1_78_0/
LIB_PATH = -LC:/Unix/boost_1_78_0/stage/lib -L.
LIBS = -llibboost_filesystem-mgw8-mt-x64-1_78 -llibboost_system-mgw8-mt-x64-1_78
SRCS = main.cpp A.cpp
OUT = out
#build executable
out:
g++ -c -Wall ${B_INCLUDE_PATH} B.cpp -o B.o
ar -rcs -o libB.lib B.o
g++ -Wall ${INCLUDE_PATH} ${LIB_PATH} ${SRCS} ${LIBS} -Wl,-Bstatic -lB -o ${OUT}
#build and run executable
run: out
./out
The following is the command prompt output:
C:\Unix\VSC\Derive_Test>mingw32-make
g++ -c -Wall -IC:/Unix/boost_1_78_0/ B.cpp -o B.o
ar -rcs -o libB.lib B.o
g++ -Wall -IC:/Unix/boost_1_78_0/ -LC:/Unix/boost_1_78_0/stage/lib -L. main.cpp A.cpp -llibboost_filesystem-mgw8-mt-x64-1_78 -llibboost_system-mgw8-mt-x64-1_78 -Wl,-Bstatic -lB -o out
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lB
collect2.exe: error: ld returned 1 exit status
mingw32-make: *** [Makefile:13: out] Error 1
I have tried renaming the output file from ar with and without the prefix lib, and with the suffixes .a, .lib, and .so, with no success.
Thank you in advance for any help.
Replace the command calls to g++ (last line in out target) with this:
g++ -Wall ${INCLUDE_PATH} ${LIB_PATH} ${SRCS} ${LIBS} -c -o main.o
g++ B.o main.o -o ${OUT}
I got it to compile; it seemed to be that ld on MinGW-w64 was looking for the specific name lib<library name>.a. I must have neglected this specific combination of prefix and suffix. Thanks for the responses.
I have file main.c, I want to create main.so.
main.c depends on libCmodel.so file.
main.c looks like
#include <stdio.h>
#include "Cmodel.h" // Must include before Amodel and Bmodel
#include "Amodel.h"
#include "Bmodel.h"
int main(){
..
return 0;
}
It can be observed that, libCmodel.so file depends on libAmodel.so.4 and libBmodelso.11.
All the "*.so" files are present in the same directory as main.c
I used the following command to generate object file
gcc -x c++ -fPIC main.c -o main.o -c -I.
I see that main.o is generated.
But, I am not sure if I have used the correct command. Is the above command correct?
Then, I tried the following commads to generate main.so ,
g++ -shared -o main.so main.o -L. -lCmodel
g++ -shared -o main.so main.o -L. -lCmodel -lAmodel -lBmodel
g++ -shared -o main.so main.o -L. -lCmodel -lAmodel.4 -lBmodel.11
g++ -shared -o main.so main.o -L. -lCmodel -lAmodel.so.4 -lBmodel.so.11
Which one of the above commands is correct?
Please help
The file containing your main function should not be a shared library. It is the entry point for an application, so it should be linked as an executable.
gcc -x c++ -I. -L. -o main main.c -lCmodel
So this is my first time making a make file so its really basic. I have 2 cpp files (functions.cpp and main.cpp) and 2 header files (structDeclaration.h and Prototypes.h). It needs to be able to compile my program but if only one file changes then it shouldn't recompile the entire thing.
heres my error:
g++ -c gradebook main.o Functions.o -I.
g++: error: gradebook: No such file or directory
make: *** [gradebook] Error 1
and heres my makefile:
CC = g++
gradebook: main.o Functions.o
g++ -c gradebook main.o Functions.o -I.
main.o: main.cpp Prototypes.h structDeclaration.h Prototypes.h
g++ -c main.cpp
Functions.o: Functions.cpp structDeclaration.h
g++ -c Functions.cpp
the commands have to be valid commands. I think you mean
g++ -o gradebook main.o Functions.o
If in doubt just try typing the command you are asking make to run for you, there is no magic involved here
i am trying to compile my c++ program and I am receiving this error.
g++ -c main.cpp
g++ -o main.o account.o checkingaccount.o savingsaccount.o -o main
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
This is the makefile I am using:
all: main
main: main.o account.o checkingaccount.o savingsaccount.o
g++ -o main.o account.o checkingaccount.o savingsaccount.o -o main
main.o: main.cpp checkingaccount.h savingsaccount.h account.h
g++ -c main.cpp
account.o: account.cpp account.h
g++ -c account.cpp
checkingaccount.o: checkingaccount.cpp checkingaccount.h account.h
g++ -c checkingaccount.cpp
savingsaccount.o: savingsaccount.cpp savingsaccount.h account.h
g++ -c savingsaccount.cpp
~
This line:
g++ -o main.o account.o checkingaccount.o savingsaccount.o -o main
... shouldn't have -o at the beginning. This specifies main.o as the name of the output file and does not link it. The second -o overrides this, but the file still isn't linked. Assuming main.cpp has your int main() function, you're not linking it in.
I am trying to compile a game using g++ and the SFML library. It works fine on Linux, but when I try to compile on Windows, the cmd floods me with error messages that all start with "player.o:player.cpp:(.text+xxxxxx):undefined reference to _imp___..."
My makefile looks like this:
all:
main.o player.o simplefunctions.o
g++ -std=c++11 main.o player.o simplefunctions.o -o climb -L C:/SFML-2.3.1/lib -lsfml-graphics -lsfml-window -lsfml-system -lsfml-network
main.o: main.cpp
g++ -std=c++11 -c main.cpp -I C:/SFML-2.3.1/include
player.o: player.cpp
g++ -std=c++11 -c player.cpp -I C:/SFML-2.3.1/include
simplefunctions.o: simplefunctions.cpp
g++ -std=c++11 -c simplefunctions.cpp -I C:/SFML-2.3.1/include
.cpp -I C:/SFML-2.3.1/include
The only difference between this and my makefile I use for the same program on ubuntu is the -I and -L tags to include the library, which I don't need on linux since it gets included automatically. All the appropriate header files are also included in the appropriate cpp's.