linker errors while compiling using makefile - c

I'm working on ubuntu 14.04 LTS and am working on a shading example program. I have the following makefile:
CC=gcc
CFLAGS=-Wall -I/usr/X11R6/include
LDFLAGS=-pthread -L/usr/X11R6/lib -lm -lGL -lglut
OBJS=main.o scene.o shader.o
glsl_lighting: $(OBJS)
$(CC) $(LDFLAGS) $(OBJS) -o glsl_lighting
clean:
rm -f glsl_lighting
rm -f $(OBJS)
main.o: main.c
scene.o: scene.c
shader.o: shader.c
With the first few lines of the main file being:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "opengl.h"
This gave the following error:
gcc -pthread -L/usr/X11R6/lib -lm -lGL -lglut main.o scene.o shader.o -o glsl_lighting
main.o: In function `handleKeyPress':
main.c:(.text+0x27): undefined reference to `glutDestroyWindow'
main.o: In function `setPerspective':
main.c:(.text+0x65): undefined reference to `tanf'
main.c:(.text+0x144): undefined reference to `glMultMatrixf'
main.o: In function `main':
main.c:(.text+0x168): undefined reference to `glutInit'
main.c:(.text+0x172): undefined reference to `glutInitDisplayMode'
main.c:(.text+0x185): undefined reference to `glutInitWindowSize'
main.c:(.text+0x18f): undefined reference to `glutCreateWindow'
main.c:(.text+0x19f): undefined reference to `glutDisplayFunc'
main.c:(.text+0x1a9): undefined reference to `glutIdleFunc'
main.c:(.text+0x1b3): undefined reference to `glutKeyboardFunc'
main.c:(.text+0x1c4): undefined reference to `glClearColor'
main.c:(.text+0x1d1): undefined reference to `glClearDepth'
main.c:(.text+0x1db): undefined reference to `glDisable'
main.c:(.text+0x1e5): undefined reference to `glEnable'
main.c:(.text+0x1ef): undefined reference to `glDepthFunc'
main.c:(.text+0x1f9): undefined reference to `glEnable'
main.c:(.text+0x203): undefined reference to `glFrontFace'
main.c:(.text+0x20d): undefined reference to `glCullFace'
main.c:(.text+0x217): undefined reference to `glMatrixMode'
main.c:(.text+0x21c): undefined reference to `glLoadIdentity'
main.c:(.text+0x25c): undefined reference to `glMatrixMode'
main.c:(.text+0x266): undefined reference to `glutMainLoop'
scene.o: In function `createCylinder':
scene.c:(.text+0xf6): undefined reference to `cosf'
scene.c:(.text+0x147): undefined reference to `sinf'
scene.c:(.text+0x179): undefined reference to `cosf'
scene.c:(.text+0x1ca): undefined reference to `sinf'
scene.c:(.text+0x201): undefined reference to `cosf'
scene.c:(.text+0x252): undefined reference to `sinf'
scene.c:(.text+0x31b): undefined reference to `glGenBuffers'
scene.c:(.text+0x332): undefined reference to `glBindBuffer'
scene.c:(.text+0x358): undefined reference to `glBufferData'
scene.c:(.text+0x36e): undefined reference to `glEnableClientState'
scene.c:(.text+0x378): undefined reference to `glEnableClientState'
scene.c:(.text+0x394): undefined reference to `glVertexPointer'
scene.c:(.text+0x3ab): undefined reference to `glNormalPointer'
scene.o: In function `sceneInit':
scene.c:(.text+0x3c4): undefined reference to `glCreateProgram'
scene.c:(.text+0x40a): undefined reference to `glLinkProgram'
scene.c:(.text+0x425): undefined reference to `glGetProgramiv'
scene.c:(.text+0x44b): undefined reference to `glGetProgramiv'
scene.c:(.text+0x479): undefined reference to `glGetProgramInfoLog'
scene.c:(.text+0x4b4): undefined reference to `glDeleteProgram'
scene.c:(.text+0x4d5): undefined reference to `glGetUniformLocation'
scene.c:(.text+0x4f2): undefined reference to `glGetUniformLocation'
scene.c:(.text+0x50f): undefined reference to `glGetUniformLocation'
scene.c:(.text+0x5c5): undefined reference to `glLoadIdentity'
scene.c:(.text+0x606): undefined reference to `glTranslatef'
scene.o: In function `sceneRender':
scene.c:(.text+0x61a): undefined reference to `glClear'
scene.c:(.text+0x62c): undefined reference to `glUseProgram'
scene.c:(.text+0x648): undefined reference to `glUniform3fv'
scene.c:(.text+0x664): undefined reference to `glUniform3fv'
scene.c:(.text+0x680): undefined reference to `glUniform3fv'
scene.c:(.text+0x697): undefined reference to `glDrawArrays'
scene.c:(.text+0x6a6): undefined reference to `glUseProgram'
scene.c:(.text+0x6b7): undefined reference to `glPushMatrix'
scene.c:(.text+0x710): undefined reference to `glTranslatef'
scene.c:(.text+0x731): undefined reference to `glColor3fv'
scene.c:(.text+0x753): undefined reference to `glutSolidSphere'
scene.c:(.text+0x758): undefined reference to `glPopMatrix'
scene.c:(.text+0x76b): undefined reference to `glutSwapBuffers'
scene.o: In function `sceneCycle':
scene.c:(.text+0x8c4): undefined reference to `cosf'
scene.c:(.text+0x8f1): undefined reference to `cosf'
scene.c:(.text+0x906): undefined reference to `sinf'
scene.c:(.text+0x933): undefined reference to `sinf'
scene.c:(.text+0x957): undefined reference to `glutPostRedisplay'
shader.o: In function `shaderCompileFromFile':
shader.c:(.text+0x213): undefined reference to `glCreateShader'
shader.c:(.text+0x241): undefined reference to `glShaderSource'
shader.c:(.text+0x250): undefined reference to `glCompileShader'
shader.c:(.text+0x274): undefined reference to `glGetShaderiv'
shader.c:(.text+0x297): undefined reference to `glGetShaderiv'
shader.c:(.text+0x2c2): undefined reference to `glGetShaderInfoLog'
shader.c:(.text+0x2fe): undefined reference to `glDeleteShader'
shader.o: In function `shaderAttachFromFile':
shader.c:(.text+0x34a): undefined reference to `glAttachShader'
shader.c:(.text+0x359): undefined reference to `glDeleteShader'
collect2: error: ld returned 1 exit status
I do have glut and mesa installed and have read on some of the other questions that you should chance something in the order of the makefile but how in this instance?

You need to put $(LDFLAGS) (libraries) after the (object) file names, like
$(CC) $(OBJS) -o glsl_lighting $(LDFLAGS)
As per the online gcc manual for linking options
[...] It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, foo.o -lz bar.o searches library z after file foo.o but before bar.o. If bar.o refers to functions in z, those functions may not be loaded.
So, the object files, using the library functions, should appear before the libraries themselves.

Related

How to fix linker errors for libudev on Ubuntu 15

I've installed libudev-dev, I can see the file /usr/lib/x86_64-linux-gnu/libudev.so but when I run gcc -Wall -ludev -o test test.c I get following error..
opensourcegeek#box:~/project/udev_device_discovery$ gcc -Wall -ludev -o test test.c
/tmp/ccg6Ydod.o: In function `main':
test.c:(.text+0xa): undefined reference to `udev_new'
test.c:(.text+0x35): undefined reference to `udev_enumerate_new'
test.c:(.text+0x4a): undefined reference to `udev_enumerate_add_match_subsystem'
test.c:(.text+0x60): undefined reference to `udev_enumerate_add_match_property'
test.c:(.text+0x76): undefined reference to `udev_enumerate_add_match_property'
test.c:(.text+0x82): undefined reference to `udev_enumerate_scan_devices'
test.c:(.text+0x8e): undefined reference to `udev_enumerate_get_list_entry'
test.c:(.text+0xab): undefined reference to `udev_list_entry_get_name'
test.c:(.text+0xc2): undefined reference to `udev_device_new_from_syspath'
test.c:(.text+0xd2): undefined reference to `udev_device_get_parent'
test.c:(.text+0xe2): undefined reference to `udev_device_get_devnode'
test.c:(.text+0x105): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x119): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x13f): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x153): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x179): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x197): undefined reference to `udev_device_unref'
test.c:(.text+0x1a3): undefined reference to `udev_list_entry_get_next'
test.c:(.text+0x1be): undefined reference to `udev_enumerate_unref'
test.c:(.text+0x1ca): undefined reference to `udev_unref'
test.c:(.text+0x1cf): undefined reference to `udev_new'
test.c:(.text+0x1fa): undefined reference to `udev_enumerate_new'
test.c:(.text+0x20f): undefined reference to `udev_enumerate_add_match_subsystem'
test.c:(.text+0x225): undefined reference to `udev_enumerate_add_match_property'
test.c:(.text+0x23b): undefined reference to `udev_enumerate_add_match_property'
test.c:(.text+0x247): undefined reference to `udev_enumerate_scan_devices'
test.c:(.text+0x253): undefined reference to `udev_enumerate_get_list_entry'
test.c:(.text+0x270): undefined reference to `udev_list_entry_get_name'
test.c:(.text+0x287): undefined reference to `udev_device_new_from_syspath'
test.c:(.text+0x297): undefined reference to `udev_device_get_devnode'
test.c:(.text+0x2ba): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x2ce): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x2f4): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x308): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x32e): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x34c): undefined reference to `udev_device_unref'
test.c:(.text+0x358): undefined reference to `udev_list_entry_get_next'
test.c:(.text+0x373): undefined reference to `udev_enumerate_unref'
test.c:(.text+0x37f): undefined reference to `udev_unref'
collect2: error: ld returned 1 exit status
I don't usually run ubuntu, but same code works on my fedora(slightly older version of libudev) and also a pi which runs wheezy (older version of libudev).
The order is important, put the library name at the end of the compilation / linking line:
$ gcc -Wall -o test test.c -ludev
The error you see is a linker error, not because of any installation issues.. Move -ludev to the end of the command line option:
gcc -Wall -o test test.c -ludev

"undefined reference" when trying to use lp_solve in C/C++ on Linux

I'm new to linear programming and C. I am trying to use the lp_solve library to solve a linear equation. The problem is I can't get the demo code to work.
As described in the documentation, I downloaded lp_solve_5.5_dev.gz to my Linux machine. I extracted the files into the same folder as my code and tried to compile:
~/Desktop/Code/CA$ cc -o demo demo.c
/tmp/ccpeN8ZV.o: In function `demo':
demo.c:(.text+0x31): undefined reference to `make_lp'
demo.c:(.text+0x62): undefined reference to `set_col_name'
demo.c:(.text+0x7d): undefined reference to `set_col_name'
demo.c:(.text+0xcf): undefined reference to `set_add_rowmode'
demo.c:(.text+0x150): undefined reference to `add_constraintex'
demo.c:(.text+0x1e6): undefined reference to `add_constraintex'
demo.c:(.text+0x274): undefined reference to `add_constraintex'
demo.c:(.text+0x29c): undefined reference to `set_add_rowmode'
demo.c:(.text+0x30b): undefined reference to `set_obj_fnex'
demo.c:(.text+0x327): undefined reference to `set_maxim'
demo.c:(.text+0x33b): undefined reference to `write_LP'
demo.c:(.text+0x34e): undefined reference to `set_verbose'
demo.c:(.text+0x359): undefined reference to `solve'
demo.c:(.text+0x383): undefined reference to `get_objective'
demo.c:(.text+0x3a6): undefined reference to `get_variables'
demo.c:(.text+0x3d2): undefined reference to `get_col_name'
demo.c:(.text+0x429): undefined reference to `delete_lp'
collect2: ld returned 1 exit status
When I add liblpsolve55.a to the command I get the following errors:
~/Desktop/Code/CA$ cc -o demo demo.c liblpsolve55.a
liblpsolve55.a(lp_lib.o): In function `scaled_floor':
lp_lib.c:(.text+0x6923): undefined reference to `floor'
liblpsolve55.a(lp_lib.o): In function `scaled_ceil':
lp_lib.c:(.text+0x6f03): undefined reference to `ceil'
liblpsolve55.a(lp_lib.o): In function `set_XLI':
lp_lib.c:(.text+0x7aa2): undefined reference to `dlclose'
lp_lib.c:(.text+0x7bb3): undefined reference to `dlopen'
lp_lib.c:(.text+0x7bd1): undefined reference to `dlsym'
lp_lib.c:(.text+0x7d8a): undefined reference to `dlsym'
lp_lib.c:(.text+0x7da6): undefined reference to `dlsym'
lp_lib.c:(.text+0x7dc2): undefined reference to `dlsym'
liblpsolve55.a(lp_lib.o): In function `set_BFP':
lp_lib.c:(.text+0x7eb4): undefined reference to `dlclose'
lp_lib.c:(.text+0x7fc3): undefined reference to `dlopen'
lp_lib.c:(.text+0x7fe1): undefined reference to `dlsym'
lp_lib.c:(.text+0x831a): undefined reference to `dlsym'
lp_lib.c:(.text+0x8336): undefined reference to `dlsym'
lp_lib.c:(.text+0x8352): undefined reference to `dlsym'
lp_lib.c:(.text+0x836e): undefined reference to `dlsym'
liblpsolve55.a(lp_lib.o):lp_lib.c:(.text+0x838a): more undefined references to `dlsym' follow
................
I understand that the lp_solve libraries are not loaded in my code. Can you please tell me how I can properly link the lp_solve libraries?
You're just missing some compiler flags to include the proper libraries. As danielko said, a quick google search on the missing libraries brings up some suggestions. E.g.
Linux c++ error: undefined reference to 'dlopen'
http://sourceforge.net/p/dev-cpp/discussion/48211/thread/3bd8b8a1
These suggest your compilation should be something more like:
cc -o demo demo.c -ldl -llpsolve55
and the lpsolve documentation suggests a command that includes the project directory such as:
cc -I/lp_solve_5.5 -I/lp_solve_5.5/bfp -I/lp_solve_5.5/bfp/bfp_etaPFI -I/lp_solve_5.5/colamd $src -o MyExe.exe -lm -ldl

Issue with lua51 c-shared library

I am trying to compile a simple example program that depends on a shared library (so) that depends on liblua51.so. My source file is example.c and here is the command I am using to compile it (it is written in C)
cc -Wall -fPIC -ldl -o a.out -I./ste-linux/ste-interface-files/c/ -L./ste-linux/ste-shared-libraries/ example.c -lm -llua51 -lste -lm -ldl
I am getting the following errors:
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `sinh'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `ceil'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `atan2'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `tanh'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `cosh'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `fmod'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `acos'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `sin'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `atan'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `asin'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `exp'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `tan'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `cos'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `log'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `pow'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `log10'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `sqrt'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `floor'
I have read a bunch of other threads on stackoverflow saying adding the -lm flag will fix this, but no matter where I put the -L and -lm -ldl in the command, these undefined references will not go away.
I am trying to compile this lib on ubuntu 12.04 LTS
Help please
The issue was the shared library I was using was built with a different version of GCC. After I downgrade from Ubuntu 11.04 (from 12.04 LTS) it was resolved.

Undefined referencs when linking to OpenGL on cygwin

I have a problem with linking while runing my Makefile. I have
installed freeglut on cygwin and tried to build my project. It works
OK in MSVS, but I get following errors:
g++ -static obj/MatrixDistortion.o obj/LookAt.o obj/MatrixT.o obj/Matrix2d.o obj/Camera.o obj/Grid.o obj/s_w_project.o obj/Scene.o -o SWproject -L/usr/lib -L/usr/X11/lib -L/lib/cygwin -L/usr/local/lib -lglut -lopengl32 -lglu32
obj/Grid.o:Grid.cpp:(.text+0xa36): undefined reference to `_glPushMatrix'
obj/Grid.o:Grid.cpp:(.text+0xa87): undefined reference to `_glMultMatrixd'
obj/Grid.o:Grid.cpp:(.text+0xaac): undefined reference to `_glTranslatef'
obj/Grid.o:Grid.cpp:(.text+0xab8): undefined reference to `_glClear'
obj/Grid.o:Grid.cpp:(.text+0xad7): undefined reference to `_glColor3f'
obj/Grid.o:Grid.cpp:(.text+0xae3): undefined reference to `_glBegin'
obj/Grid.o:Grid.cpp:(.text+0xb2c): undefined reference to `_glVertex3f'
obj/Grid.o:Grid.cpp:(.text+0xb4f): undefined reference to `_glVertex3f'
obj/Grid.o:Grid.cpp:(.text+0xbb4): undefined reference to `_glVertex3f'
obj/Grid.o:Grid.cpp:(.text+0xbd7): undefined reference to `_glVertex3f'
obj/Grid.o:Grid.cpp:(.text+0xc1e): undefined reference to `_glColor3f'
obj/Grid.o:Grid.cpp:(.text+0xc3d): undefined reference to `_glVertex3f'
obj/Grid.o:Grid.cpp:(.text+0xc5c): undefined reference to `_glVertex3f'
obj/Grid.o:Grid.cpp:(.text+0xc7b): undefined reference to `_glColor3f'
obj/Grid.o:Grid.cpp:(.text+0xc9a): undefined reference to `_glVertex3f'
obj/Grid.o:Grid.cpp:(.text+0xcb9): undefined reference to `_glVertex3f'
obj/Grid.o:Grid.cpp:(.text+0xcd8): undefined reference to `_glColor3f'
obj/Grid.o:Grid.cpp:(.text+0xcf7): undefined reference to `_glVertex3f'
obj/Grid.o:Grid.cpp:(.text+0xd16): undefined reference to `_glVertex3f'
obj/Grid.o:Grid.cpp:(.text+0xd1b): undefined reference to `_glEnd'
obj/Grid.o:Grid.cpp:(.text+0xd20): undefined reference to `_glPopMatrix'
obj/Grid.o:Grid.cpp:(.text+0xd25): undefined reference to `_glFlush'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld: obj/Grid.o: bad reloc address 0xd in section `.text$_ZNSt4listIP6CameraSaIS1_EED1Ev[std::list<Camera*, std::allocator<Camera*> >::~list()]'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld: final link failed: Invalid operation
collect2: ld returned 1 exit status
Makefile:14: recipe for target `SWproject' failed
I have passed the libraries to g++ as can be seen in the compiler invocation.
Do I have to install GL separately, but in that case why don't I get an error on #include <GL/gl.h>?

MinGW/libssl Linking Errors

I am porting an application that I developed in Linux to Windows and am having some issues when building the application. After making the necessary code changes, everything compiles fine (and when built as a debug build in Visual Studio, runs without any issues). I need to build this in MinGW, and I'm having linker errors when I try to link it against liboauth, which is also required for my project.
The command and its output are as follows:
gcc application.o service.o util.o json.o api.o -L/usr/local/lib -lcrypto -lssl -lcurl -ljansson -loauth -Wl -o application
C:/MinGW/msys/1.0/local/lib/liboauth.a(liboauth_la-hash.o): In function `oauth_sign_hmac_sha1_raw':
c:\lib\liboauth-0.9.4\src/hash.c:314: undefined reference to `EVP_sha1'
c:\lib\liboauth-0.9.4\src/hash.c:314: undefined reference to `HMAC'
C:/MinGW/msys/1.0/local/lib/liboauth.a(liboauth_la-hash.o): In function `oauth_sign_rsa_sha1':
c:\lib\liboauth-0.9.4\src/hash.c:334: undefined reference to `BIO_new_mem_buf'
c:\lib\liboauth-0.9.4\src/hash.c:335: undefined reference to `PEM_read_bio_PrivateKey'
c:\lib\liboauth-0.9.4\src/hash.c:336: undefined reference to `BIO_free'
c:\lib\liboauth-0.9.4\src/hash.c:343: undefined reference to `EVP_PKEY_size'
c:\lib\liboauth-0.9.4\src/hash.c:346: undefined reference to `EVP_sha1'
c:\lib\liboauth-0.9.4\src/hash.c:346: undefined reference to `EVP_DigestInit'
c:\lib\liboauth-0.9.4\src/hash.c:347: undefined reference to `EVP_DigestUpdate'
c:\lib\liboauth-0.9.4\src/hash.c:348: undefined reference to `EVP_SignFinal'
c:\lib\liboauth-0.9.4\src/hash.c:352: undefined reference to `CRYPTO_free'
c:\lib\liboauth-0.9.4\src/hash.c:353: undefined reference to `EVP_PKEY_free'
C:/MinGW/msys/1.0/local/lib/liboauth.a(liboauth_la-hash.o): In function `oauth_verify_rsa_sha1':
c:\lib\liboauth-0.9.4\src/hash.c:367: undefined reference to `BIO_new_mem_buf'
c:\lib\liboauth-0.9.4\src/hash.c:368: undefined reference to `PEM_read_bio_X509'
c:\lib\liboauth-0.9.4\src/hash.c:370: undefined reference to `X509_get_pubkey'
c:\lib\liboauth-0.9.4\src/hash.c:371: undefined reference to `X509_free'
c:\lib\liboauth-0.9.4\src/hash.c:375: undefined reference to `BIO_free'
c:\lib\liboauth-0.9.4\src/hash.c:384: undefined reference to `EVP_sha1'
c:\lib\liboauth-0.9.4\src/hash.c:384: undefined reference to `EVP_DigestInit'
c:\lib\liboauth-0.9.4\src/hash.c:385: undefined reference to `EVP_DigestUpdate'
c:\lib\liboauth-0.9.4\src/hash.c:386: undefined reference to `EVP_VerifyFinal'
c:\lib\liboauth-0.9.4\src/hash.c:387: undefined reference to `EVP_MD_CTX_cleanup'
c:\lib\liboauth-0.9.4\src/hash.c:388: undefined reference to `EVP_PKEY_free'
c:\lib\liboauth-0.9.4\src/hash.c:373: undefined reference to `PEM_read_bio_PUBKEY'
C:/MinGW/msys/1.0/local/lib/liboauth.a(liboauth_la-hash.o): In function `oauth_body_hash_file':
c:\lib\liboauth-0.9.4\src/hash.c:405: undefined reference to `EVP_MD_CTX_init'
c:\lib\liboauth-0.9.4\src/hash.c:406: undefined reference to `EVP_sha1'
c:\lib\liboauth-0.9.4\src/hash.c:406: undefined reference to `EVP_DigestInit'
c:\lib\liboauth-0.9.4\src/hash.c:408: undefined reference to `EVP_DigestUpdate'
c:\lib\liboauth-0.9.4\src/hash.c:412: undefined reference to `EVP_sha1'
c:\lib\liboauth-0.9.4\src/hash.c:412: undefined reference to `EVP_MD_size'
c:\lib\liboauth-0.9.4\src/hash.c:413: undefined reference to `EVP_DigestFinal'
c:\lib\liboauth-0.9.4\src/hash.c:414: undefined reference to `EVP_MD_CTX_cleanup'
C:/MinGW/msys/1.0/local/lib/liboauth.a(liboauth_la-hash.o): In function `oauth_body_hash_data':
c:\lib\liboauth-0.9.4\src/hash.c:422: undefined reference to `EVP_sha1'
c:\lib\liboauth-0.9.4\src/hash.c:422: undefined reference to `EVP_MD_size'
c:\lib\liboauth-0.9.4\src/hash.c:423: undefined reference to `EVP_MD_CTX_init'
c:\lib\liboauth-0.9.4\src/hash.c:424: undefined reference to `EVP_sha1'
c:\lib\liboauth-0.9.4\src/hash.c:424: undefined reference to `EVP_DigestInit'
c:\lib\liboauth-0.9.4\src/hash.c:425: undefined reference to `EVP_DigestUpdate'
c:\lib\liboauth-0.9.4\src/hash.c:426: undefined reference to `EVP_DigestFinal'
c:\lib\liboauth-0.9.4\src/hash.c:427: undefined reference to `EVP_MD_CTX_cleanup'
collect2: ld returned 1 exit status
make: *** [montools] Error 1
I have all of the required libraries in the lib path, and for some reason liboauth just cannot find the references to libssl and libcrypto. This all builds fine in Linux. Any ideas?
Update
Based on responses, I have updated my linker command so as to link the libraries in a different order. My new command is as follows:
gcc -o application application.o service.o util.o json.o api.o -Lc:/mingw/msys/1.0/local/lib -loauth -ljansson -lcurl -lssl -lcrypto
This fixes this previous problem and presents a new set of linker errors:
gcc -o application application.o service.o util.o json.o api.o -Lc:/mingw/msys/1.0/local/lib -loauth -ljansson -lcurl -lssl -lcrypto
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xee0): undefined reference to `CreateDCA#16'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xeef): undefined reference to `CreateCompatibleDC#4'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xf08): undefined reference to `GetDeviceCaps#8'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xf23): undefined reference to `GetDeviceCaps#8'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xf44): undefined reference to `CreateCompatibleBitmap#12'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xf5b): undefined reference to `SelectObject#8'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xf7e): undefined reference to `GetObjectA#12'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x1024): undefined reference to `BitBlt#36'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x103b): undefined reference to `GetBitmapBits#12'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x10b0): undefined reference to `SelectObject#8'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x10bb): undefined reference to `DeleteObject#4'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x10c8): undefined reference to `DeleteDC#4'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x10d5): undefined reference to `DeleteDC#4'
collect2: ld returned 1 exit status
make: *** [montools] Error 1
A quick google search returned that I should also link in the gdi32 library (for purposes unrelated to my tasks. The final command for the linker is then as follows:
gcc -o application application.o service.o util.o json.o api.o -Lc:/mingw/msys/1.0/local/lib -loauth -ljansson -lcurl -lssl -lcrypto -lgdi32
Try this:
gcc -o application application.o service.o util.o json.o api.o -Lc:/mingw/msys/1.0/local/lib -loauth -ljansson -lcurl -lssl -lcrypto

Resources