UART on SAM4SxPLAINED - c++

UART on SAM4SxPLAINED
Hello,
I have a program which (almost) works !
The characters are transmitted but they are not still the ones hoped.
Who can correct?
Thank you for everything.
Greetings.
Voici le code :
#include "sam.h"
// Fréquence d'horloge
#define MCLK CHIP_FREQ_MAINCK_RC_4MHZ
// Configure UART
#define BAUD 115200
#define PARITY UART_MR_PAR_NO
//#define PARITY UART_MR_PAR_EVEN
// Définitions pour PA9 comme RX_UART0 et PA10 comme TX_UART0 (Périphérique A).
#define RXTX_PIO PIOA
#define RX_PIN PIO_PA9
#define TX_PIN PIO_PA10
#define UART UART0
#define UART_PID ID_UART0
#define RXTX_IRQn PIOA_IRQn
#define UART_IRQn UART0_IRQn
//prototype pour les fonctions. On ne veut pas faire un .h pour ça !
void hardware_init( void ) ;
void hardware_init( void )
{
//pour utiliser RX_UART et TX_UART.
PMC->PMC_PCER0 = (1 << UART_PID) ;
RXTX_PIO->PIO_IDR |= RX_PIN | TX_PIN ;
// Sélectionne le périphérique A
RXTX_PIO->PIO_ABCDSR[0] &= ~(RX_PIN | TX_PIN) ;
RXTX_PIO->PIO_ABCDSR[1] &= ~(RX_PIN | TX_PIN) ;
RXTX_PIO->PIO_PDR = (RX_PIN | TX_PIN) ;
//Configure UART
UART->UART_BRGR= MCLK / (BAUD * 16) ;
UART->UART_CR = UART_CR_TXEN | UART_CR_RXEN ;
UART->UART_IER = UART_IER_RXRDY ;
// Active les interruptions sur UART;
NVIC_EnableIRQ( UART_IRQn ) ;
// Configure Systick pour un déclenchement chaque milliseconde
SysTick_Config( SystemCoreClock/1000UL ) ;
NVIC_EnableIRQ( SysTick_IRQn ) ;
}
// Variable globale pour compter les tics
static uint32_t ul_tickcount=0 ;
// Variable globale pour UART_Handler
static int32_t tr ;
static uint32_t j = 0 ;
static char chaine[] = "Bonjour UART0 " ;
static uint8_t nb_car = 14 ; //nombre de caractères de chaine
void SysTick_Handler( void )
{
ul_tickcount++ ;
// envoie un caractère toutes les secondes (ie 1000ms)
if ( ul_tickcount == 1000)
{
if (j == nb_car)
{
j=0;
}
while(!(UART->UART_SR & UART_SR_TXRDY)) ;
UART->UART_THR = chaine[j] ;
j++ ;
ul_tickcount = 0 ;
}
}
void UART0_Handler( void )
{
if (UART->UART_SR & UART_SR_RXRDY)
{
tr = UART->UART_RHR ;
while(!(UART->UART_SR & UART_SR_TXRDY));
UART->UART_THR = tr - 1 ;
}
}
int main (void)
{
hardware_init() ;
while ( 1 )
{
}
}

Related

couldn't create a lua module in C++ (can't include local header)

I'm using vs code and g++ to compile c++, however I can't include lua.h, lauxlib.h, lualib.h etc.
this is the terminal (using vscode terminal):
C:\MingW\bin> .\g++ C:\Users\leand\Desktop\VSCODE\cpp\template.cpp -o C:\Users\leand\Desktop\VSCODE\cpp\build.exe -I C:\Users\leand\Desktop\VSCODE\cpp\
C:\Users\leand\AppData\Local\Temp\cc6kM8pM.o:template.cpp:(.text+0x1d): undefined reference to `lua_tonumberx'
C:\Users\leand\AppData\Local\Temp\cc6kM8pM.o:template.cpp:(.text+0x3b): undefined reference to `lua_tonumberx'
C:\Users\leand\AppData\Local\Temp\cc6kM8pM.o:template.cpp:(.text+0x59): undefined reference to `lua_pushnumber'
C:\Users\leand\AppData\Local\Temp\cc6kM8pM.o:template.cpp:(.text+0x9f): undefined reference to `luaL_checkversion_'
C:\Users\leand\AppData\Local\Temp\cc6kM8pM.o:template.cpp:(.text+0xba): undefined reference to `lua_createtable'
C:\Users\leand\AppData\Local\Temp\cc6kM8pM.o:template.cpp:(.text+0xd4): undefined reference to `luaL_setfuncs'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
this is the folder (C:\Users\leand\Desktop\VSCODE\cpp)
this is my code
#ifdef __cplusplus
extern "C" {
#endif
#include "luaconf.h"
#include "lualib.h"
#include "lauxlib.h"
#include "lua.h"
int soma(lua_State *L) {
double nl = lua_tonumber(L, 1);
double n2 = lua_tonumber(L, 2);
double resultado = nl + n2;
lua_pushnumber(L, resultado); /* Empurra para o stack do Lua o valor resultado return 1; /* Informa quantas variáveis estão sendo retornadas para o Lua */
return 1; // quantas variaveis retornam para o Lua
}
int luaopen_template(lua_State *L){ /* lua_State *L é um tipo de ponteiro específico para a API do Lua */
luaL_Reg funcoes[] = { /* Recurso para listar funções C que devem ser levadas para o Lua */
{"soma", soma},
{NULL, NULL} /* Indicador que a lista acabou */
};
luaL_newlib(L, funcoes); /* Define uma nova biblioteca Lua com as funções passadas por Lual_Reg */
return 1;
}
#ifdef __cplusplus
}
#endif

Intel PARDISO factorization slower when linking dynamically

We have a code that runs PARDISO solver. When we link this code statically, the factorization step is 2x faster than when we link the same code dinamically.
Here are link lines obtained from CMake in both cases (I've used the MKL link line advisor to help me define the parameters):
Static linking:
/opt/intel/compilers_and_libraries_2016/linux/bin/intel64/icpc -rdynamic CMakeFiles/simplesolver.dir/pardiso_sym_c.cpp.o -o simplesolver -Wl,--start-group /opt/intel/compilers_and_libraries_2016/linux/mkl/lib/intel64/libmkl_intel_lp64.a /opt/intel/compilers_and_libraries_2016/linux/mkl/lib/intel64/libmkl_intel_thread.a /opt/intel/compilers_and_libraries_2016/linux/mkl/lib/intel64/libmkl_core.a -Wl,--end-group -liomp5 -lpthread -lm -ldl
Dynamic linking:
/opt/intel/compilers_and_libraries_2016/linux/bin/intel64/icpc
-rdynamic CMakeFiles/simplesolver.dir/pardiso_sym_c.cpp.o -o simplesolver
-L/opt/intel/compilers_and_libraries_2016/linux/mkl/lib/intel64 -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -liomp5 -lpthread -lm -ldl
Is there any known issue with this? or we are missing some compilation/linking flags to improve factorization performance? The code is exactly the same (solverc example from the MKL distribution). The only thing we change is how to link, and then we obtain this big difference in running speed.
We are using Intel Compiler C++ 2016 and using the MKL from it, under Linux (Ubuntu 14.04). We measure the time by looking at the output of PARDISO (msglvl=1).
Only if it helps, this is the code (I've ommited the function readData that reads the matrix information from a file).
#include "mkl_pardiso.h"
#include "mkl_types.h"
#include <cmath>
#include <iomanip>
#include <iostream>
#include <fstream>
#include <string>
MKL_INT main (void)
{
int n; // dimension of matrix
int nnz; // number of non zeroes
int* ia; // coordinates in i of each value in a
int* ja; // coordinates in j of each value in a
double* a; // values of the matrix
double* b; // vector of forces
double* x_expected; // computed solution our software (Ax=rhs)
double* x; // computed solution in pardiso
bool result = false;
std::string fileIn = "problemData.bin";
//METHOD THAT FILLS ALL THE VALUES... NOT RELEVANT.
result = readData(fileIn, n, nnz, &ia, &ja, &a, &b, &x_expected, false);
x = new double[n];
if (!result)
return 1;
MKL_INT mtype = -2; /* Real symmetric matrix */
/* RHS and solution vectors. */
MKL_INT nrhs = 1; /* Number of right hand sides. */
/* Internal solver memory pointer pt, */
/* 32-bit: int pt[64]; 64-bit: long int pt[64] */
/* or void *pt[64] should be OK on both architectures */
void *pt[64];
/* Pardiso control parameters. */
MKL_INT iparm[64];
MKL_INT maxfct, mnum, phase, error, msglvl;
/* Auxiliary variables. */
MKL_INT i;
double ddum; /* Double dummy */
MKL_INT idum; /* Integer dummy. */
/* -------------------------------------------------------------------- */
/* .. Setup Pardiso control parameters. */
/* -------------------------------------------------------------------- */
for ( i = 0; i < 64; i++ )
{
iparm[i] = 0;
}
iparm[0] = 1; /* No solver default */
iparm[1] = 2; /* Fill-in reordering from METIS */
iparm[3] = 0; /* No iterative-direct algorithm */
iparm[4] = 0; /* No user fill-in reducing permutation */
iparm[5] = 0; /* Write solution into x */
iparm[6] = 0; /* Not in use */
iparm[7] = 2; /* Max numbers of iterative refinement steps */
iparm[8] = 0; /* Not in use */
iparm[9] = 13; /* Perturb the pivot elements with 1E-13 */
iparm[10] = 1; /* Use nonsymmetric permutation and scaling MPS */
iparm[11] = 0; /* Not in use */
iparm[12] = 0; /* Maximum weighted matching algorithm is switched-off (default for symmetric). Try iparm[12] = 1 in case of inappropriate accuracy */
iparm[13] = 0; /* Output: Number of perturbed pivots */
iparm[14] = 0; /* Not in use */
iparm[15] = 0; /* Not in use */
iparm[16] = 0; /* Not in use */
iparm[17] = -1; /* Output: Number of nonzeros in the factor LU */
iparm[18] = -1; /* Output: Mflops for LU factorization */
iparm[19] = 0; /* Output: Numbers of CG Iterations */
maxfct = 1; /* Maximum number of numerical factorizations. */
mnum = 1; /* Which factorization to use. */
msglvl = 1; /* Print statistical information in file */
error = 0; /* Initialize error flag */
/* -------------------------------------------------------------------- */
/* .. Initialize the internal solver memory pointer. This is only */
/* necessary for the FIRST call of the PARDISO solver. */
/* -------------------------------------------------------------------- */
for ( i = 0; i < 64; i++ )
{
pt[i] = 0;
}
/* -------------------------------------------------------------------- */
/* .. Reordering and Symbolic Factorization. This step also allocates */
/* all memory that is necessary for the factorization. */
/* -------------------------------------------------------------------- */
phase = 11;
PARDISO (pt, &maxfct, &mnum, &mtype, &phase,
&n, a, ia, ja, &idum, &nrhs, iparm, &msglvl, &ddum, &ddum, &error);
if ( error != 0 )
{
printf ("\nERROR during symbolic factorization: %d", error);
return -1;
}
printf ("\nReordering completed ... ");
printf ("\nNumber of nonzeros in factors = %d", iparm[17]);
printf ("\nNumber of factorization MFLOPS = %d", iparm[18]);
/* -------------------------------------------------------------------- */
/* .. Numerical factorization. */
/* -------------------------------------------------------------------- */
phase = 22;
PARDISO (pt, &maxfct, &mnum, &mtype, &phase,
&n, a, ia, ja, &idum, &nrhs, iparm, &msglvl, &ddum, &ddum, &error);
if ( error != 0 )
{
printf ("\nERROR during numerical factorization: %d", error);
return -2;
}
printf ("\nFactorization completed ... ");
/* -------------------------------------------------------------------- */
/* .. Back substitution and iterative refinement. */
/* -------------------------------------------------------------------- */
phase = 33;
iparm[7] = 2; /* Max numbers of iterative refinement steps. */
PARDISO (pt, &maxfct, &mnum, &mtype, &phase,
&n, a, ia, ja, &idum, &nrhs, iparm, &msglvl, b, x, &error);
if ( error != 0 )
{
printf ("\nERROR during solution: %d", error);
return -3;
}
printf ("\nSolve completed ... ");
/* -------------------------------------------------------------------- */
/* .. Termination and release of memory. */
/* -------------------------------------------------------------------- */
phase = -1; /* Release internal memory. */
PARDISO (pt, &maxfct, &mnum, &mtype, &phase,
&n, &ddum, ia, ja, &idum, &nrhs,
iparm, &msglvl, &ddum, &ddum, &error);
delete [] ia;
delete [] ja;
delete [] a;
delete [] b;
delete [] x;
delete [] x_expected;
return 0;
}
You have turned on 0 optimisations. A lot of factors would then contribute to runtime behaviour that are not at all related to MKL / dynamic vs static linking etc. What happens, when you compile above code with -O2 -g -march=native, -O3 -march=native? The differences should go away entirely.

ld ignores additional pathes

I'm am trying to compile a C++ program that uses Gurobi. The problem is that ld cannot find the library although ldconfig sees it. I also tried to configure the LD_LIBRARY_PATH variable without success
$ sudo ldconfig -v
...
/opt/gurobi701/linux64/lib:
libgurobi.so.7.0.1 -> libgurobi.so.7.0.1
libaes70.so -> libaes70.so
libGurobiJni70.so -> libGurobiJni70.so
...
$ echo $LD_LIBRARY_PATH
:/opt/gurobi701/linux64/lib
$ ld -lgurobi_c++ --verbose
GNU ld (GNU Binutils for Ubuntu) 2.26.1
Émulations prises en charge :
elf_x86_64
elf32_x86_64
elf_i386
elf_iamcu
i386linux
elf_l1om
elf_k1om
i386pep
i386pe
utilisation du script interne d'édition de liens :
==================================================
/* Script for -z combreloc: combine and sort reloc sections */
/* Copyright (C) 2014-2015 Free Software Foundation, Inc.
Copying and distribution of this script, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. */
OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64",
"elf64-x86-64")
OUTPUT_ARCH(i386:x86-64)
ENTRY(_start)
SEARCH_DIR("=/usr/local/lib/x86_64-linux-gnu"); SEARCH_DIR("=/lib/x86_64-linux-gnu"); SEARCH_DIR("=/usr/lib/x86_64-linux-gnu"); SEARCH_DIR("=/usr/local/lib64"); SEARCH_DIR("=/lib64"); SEARCH_DIR("=/usr/lib64"); SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib"); SEARCH_DIR("=/usr/x86_64-linux-gnu/lib64"); SEARCH_DIR("=/usr/x86_64-linux-gnu/lib");
SECTIONS
{
/* Read-only sections, merged into text segment: */
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x400000) + SIZEOF_HEADERS;
.interp : { *(.interp) }
.note.gnu.build-id : { *(.note.gnu.build-id) }
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d : { *(.gnu.version_d) }
.gnu.version_r : { *(.gnu.version_r) }
.rela.dyn :
{
*(.rela.init)
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
*(.rela.fini)
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
*(.rela.ctors)
*(.rela.dtors)
*(.rela.got)
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
*(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*)
*(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*)
*(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*)
*(.rela.ifunc)
}
.rela.plt :
{
*(.rela.plt)
PROVIDE_HIDDEN (__rela_iplt_start = .);
*(.rela.iplt)
PROVIDE_HIDDEN (__rela_iplt_end = .);
}
.init :
{
KEEP (*(SORT_NONE(.init)))
}
.plt : { *(.plt) *(.iplt) }
.plt.got : { *(.plt.got) }
.plt.bnd : { *(.plt.bnd) }
.text :
{
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
*(.text.exit .text.exit.*)
*(.text.startup .text.startup.*)
*(.text.hot .text.hot.*)
*(.text .stub .text.* .gnu.linkonce.t.*)
/* .gnu.warning sections are handled specially by elf32.em. */
*(.gnu.warning)
}
.fini :
{
KEEP (*(SORT_NONE(.fini)))
}
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
.rodata1 : { *(.rodata1) }
.eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table
.gcc_except_table.*) }
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) }
/* These sections are generated by the Sun/Oracle C++ compiler. */
.exception_ranges : ONLY_IF_RO { *(.exception_ranges
.exception_ranges*) }
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
. = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
/* Exception handling */
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gnu_extab : ONLY_IF_RW { *(.gnu_extab) }
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
.exception_ranges : ONLY_IF_RW { *(.exception_ranges .exception_ranges*) }
/* Thread Local Storage sections */
.tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
}
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
}
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
}
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
}
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
}
.jcr : { KEEP (*(.jcr)) }
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
.dynamic : { *(.dynamic) }
.got : { *(.got) *(.igot) }
. = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 24 ? 24 : 0, .);
.got.plt : { *(.got.plt) *(.igot.plt) }
.data :
{
*(.data .data.* .gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
}
.data1 : { *(.data1) }
_edata = .; PROVIDE (edata = .);
. = .;
__bss_start = .;
.bss :
{
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
/* Align here to ensure that the .bss section occupies space up to
_end. Align after .bss to ensure correct alignment even if the
.bss section disappears because there are no input sections.
FIXME: Why do we need it? When there is no .bss section, we don't
pad the .data section. */
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
.lbss :
{
*(.dynlbss)
*(.lbss .lbss.* .gnu.linkonce.lb.*)
*(LARGE_COMMON)
}
. = ALIGN(64 / 8);
. = SEGMENT_START("ldata-segment", .);
.lrodata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.lrodata .lrodata.* .gnu.linkonce.lr.*)
}
.ldata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.ldata .ldata.* .gnu.linkonce.l.*)
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
. = ALIGN(64 / 8);
_end = .; PROVIDE (end = .);
. = DATA_SEGMENT_END (.);
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end ) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
/* DWARF 3 */
.debug_pubtypes 0 : { *(.debug_pubtypes) }
.debug_ranges 0 : { *(.debug_ranges) }
/* DWARF Extension. */
.debug_macro 0 : { *(.debug_macro) }
.gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
}
==================================================
échec de la tentative d'ouverture de //usr/local/lib/x86_64-linux-gnu/libgurobi_c++.so
échec de la tentative d'ouverture de //usr/local/lib/x86_64-linux-gnu/libgurobi_c++.a
échec de la tentative d'ouverture de //lib/x86_64-linux-gnu/libgurobi_c++.so
échec de la tentative d'ouverture de //lib/x86_64-linux-gnu/libgurobi_c++.a
échec de la tentative d'ouverture de //usr/lib/x86_64-linux-gnu/libgurobi_c++.so
échec de la tentative d'ouverture de //usr/lib/x86_64-linux-gnu/libgurobi_c++.a
échec de la tentative d'ouverture de //usr/local/lib64/libgurobi_c++.so
échec de la tentative d'ouverture de //usr/local/lib64/libgurobi_c++.a
échec de la tentative d'ouverture de //lib64/libgurobi_c++.so
échec de la tentative d'ouverture de //lib64/libgurobi_c++.a
échec de la tentative d'ouverture de //usr/lib64/libgurobi_c++.so
échec de la tentative d'ouverture de //usr/lib64/libgurobi_c++.a
échec de la tentative d'ouverture de //usr/local/lib/libgurobi_c++.so
échec de la tentative d'ouverture de //usr/local/lib/libgurobi_c++.a
échec de la tentative d'ouverture de //lib/libgurobi_c++.so
échec de la tentative d'ouverture de //lib/libgurobi_c++.a
échec de la tentative d'ouverture de //usr/lib/libgurobi_c++.so
échec de la tentative d'ouverture de //usr/lib/libgurobi_c++.a
échec de la tentative d'ouverture de //usr/x86_64-linux-gnu/lib64/libgurobi_c++.so
échec de la tentative d'ouverture de //usr/x86_64-linux-gnu/lib64/libgurobi_c++.a
échec de la tentative d'ouverture de //usr/x86_64-linux-gnu/lib/libgurobi_c++.so
échec de la tentative d'ouverture de //usr/x86_64-linux-gnu/lib/libgurobi_c++.a
ld : ne peut trouver -lgurobi_c++
Any ideas?
LD_LIBRARY_PATH is the path where the dynamic loader (ld.so and ld-linux.so on Linux, dyld on OS X) looks up libraries. You need this when you run programs that depend on libraries in non-standard paths.
It doesn't necessarily influence where the linker finds libraries. Use the -L flag to specify the search path for ld:
ld -L/opt/gurobi701/linux64/lib -lgurobi_c++ ...

Undefined reference when a function is listed in a header file, but fine if I copy and paste code directly

I am working on a large project in C++ that is proprietary, so I can't actually share the source code. I have most of the code compiled, but there is one function, in a particular file, that is giving me quite a bit of trouble.
I've created a simple example that shows what the problem is. We have:
WTPSHORT.H
#ifndef WTP_H
#define WTP_H 1
#define VERSION "Version 2.1"
#define DATE "Nov., 2001"
/* ANSI C header files */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <fcntl.h>
#include <ctype.h>
#define TRUE 1
#define FALSE 0
/************ Data structures for Water Treatment Plant ***************/
struct Effluent { /****** Data Packet for All Unit Processes *******/
/* Operating data: */
double DegK; /* Temperature (Deg K) */
double Flow; /* Average flow (MGD) */
double Peak; /* Max hourly flow (MDG) */
/* Unit process counters: */
short cl2cnt; /* Number of times chlorine added. */
/* Measurable Water Quality Parameters: */
double pH; /* [H+]=pow(10,-pH) (-) */
/* More variable definitions go here */
double beta_br; /* Constant for chlorine to bromine reactivity ratio */
double time_step; /* Time step (hrs) */
}; /************ End of struct Effluent ************/
/*****************************************/
struct ProcessTrain { /* Control Structure for Process Train */
struct UnitProcess *head; /* First UnitProcess in ProcessTrain */
struct UnitProcess *null; /* Always NULL */
struct UnitProcess *tail; /* Last UnitProcess in ProcessTrain */
char file_name[120]; /* Full path and extension */
}; /*****************************************/
struct UnitProcess { /********** Treatment Process ***************/
struct UnitProcess *next; /* Double Linked list */
struct UnitProcess *prev; /* " " " */
short type; /* Defined unit process types */
short pad; /* Maintain 32 bit alinment of pointers */
union { /* Design and operating parameters: */
void *ptr;
struct Influent *influent;
struct Mechdbp *mechdbp; //FOR MECH MODEL
struct Alum *alum;
struct Gac *gac;
struct Filter *filter;
struct Basin *basin;
// struct Membrane *membrane;
struct Mfuf *mfuf;
struct Nf *nf;
struct Iron *iron;
struct chemical *chemical;
struct clo2 *clo2;
struct lime *lime;
/*struct WTP_effluent *wtp_effluent; No longer needed - WJS, 11/98 */
struct Avg_tap *avg_tap;
struct End_of_system *end_of_system;
} data;
struct Effluent eff;
};
struct Influent { /* Raw Water Data */
double pH; /* (-) */
double temp; /* Average temperature (C) */
double low_temp; /* Low temperature for disinfection (C) */
double toc; /* (mg/L) */
double uv254; /* (1/cm) */
double bromide; /* (mg/L) */
double alkalinity; /* (mg/L as CaCO3) */
double calcium; /* Calcium Hardness (mg/L as CaCO3) */
double hardness; /* Total Hardness (mg/L as CaCO3) */
double nh3; /* Ammonia (mg/L as N) */
double ntu; /* Turbidity */
double crypto_req; /* Crypto Log removal + Log Inact. required*/
double clo2_crypto_ct_mult; /* Multiplier */
double peak_flow; /* Peak Hourly Flow for disinfection (MGD) */
double avg_flow; /* Average Flow (MGD) */
int swflag; /* TRUE=Surface Water; FALSE=Ground Water */
// char *run_name;
};
void s1_s2_est(struct UnitProcess *unit);
/* define(s) for UnitProcess.type */
#define VACANT 0
#define INFLUENT 1
#define RAPID_MIX 2
#define SLOW_MIX 3
#define SETTLING_BASIN 4
#define FILTER 5
#define BASIN 6
#define CONTACT_TANK 7
#define CLEARWELL 8
#define O3_CONTACTOR 9
#define GAC 10
#define MFUF_UP 11
#define NF_UP 12
#endif
And then there are two source files in the project:
s1s2_est.c
/* s1s2_est.c -- December, 2000*/
#include "WTPSHORT.H"
void s1_s2_est(struct UnitProcess *unit)
{
double toc, uva, s1_0, s2h_0, s2star_0, s2t_0, s1_f, s2h_f, s2star_f, s2t_f, H;
struct Effluent *eff;
eff = &unit->eff;
/* Get these inputs */
toc = eff->TOC;
uva = eff->UV;
s1_0 = eff->s1;
s2h_0 = eff->s2h;
s2star_0 = eff->s2_star;
H = pow(10.0, -eff->pH);
s2t_0 = s2h_0 + s2star_0;
s1_f = s1_0;
s2t_f = s2t_0;
s2star_f = s2star_0;
s2h_f = s2h_0;
if(eff->s1_s2_estflag == 'C')
{
/* Safety check */
if (toc < 0.0) toc = 0.0;
if (uva < 0.0) uva = 0.0;
s1_f = 5.05 * pow(toc, 0.57) * pow(uva, 0.54);
s2t_f = 13.1 * pow(toc, 0.38) * pow(uva, 0.40);
/* No increases in the S values allowed */
if(s1_f > s1_0 ) s1_f = s1_0;
if(s2t_f > s2t_0) s2t_f = s2t_0;
/* Speciate S2 */
s2h_f = s2t_f * eff->k21r * H / (eff->k21f + eff->k21r * H);
s2star_f = s2t_f * eff->k21f / (eff->k21f + eff->k21r * H);
}
if(eff->s1_s2_estflag != 'C' && unit->type == INFLUENT)
{/* Speciate S2 in raw water*/
s2h_f = s2t_f * eff->k21r * H / (eff->k21f + eff->k21r * H);
s2star_f = s2t_f * eff->k21f / (eff->k21f + eff->k21r * H);
}
/* Update Effluent data structure */
eff->s1 = s1_f;
eff->s2h = s2h_f;
eff->s2_star = s2star_f;
}/* End subroutine "s1_s2_est()"*/
and then
main.cpp
#include <stdio.h>
#include "WTPSHORT.H"
int main(int argc, char **argv)
{
UnitProcess *myunit;
s1_s2_est(myunit);
printf("done\n");
return 0;
}
When compiling and linking I see this error:
C:\WINDOWS\system32\cmd.exe /C "C:/MinGW/bin/mingw32-make.exe -j8 SHELL=cmd.exe -e -f Makefile"
"----------Building project:[ simple - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'C:/Users/joka0958/Desktop/wtp/compiledwtp/simple'
C:/MinGW/bin/g++.exe -c "C:/Users/joka0958/Desktop/wtp/compiledwtp/simple/main.cpp" -g -O0 -Wall -o ./Debug/main.cpp.o -I. -I.
C:/MinGW/bin/gcc.exe -c "C:/Users/joka0958/Desktop/wtp/compiledwtp/simple/s1s2_est.c" -g -O0 -Wall -o ./Debug/s1s2_est.c.o -I. -I.
C:/Users/joka0958/Desktop/wtp/compiledwtp/simple/main.cpp: In function 'int main(int, char**)':
C:/Users/joka0958/Desktop/wtp/compiledwtp/simple/main.cpp:7:22: warning: 'myunit' is used uninitialized in this function [-Wuninitialized]
s1_s2_est(myunit);
^
C:/MinGW/bin/g++.exe -o ./Debug/simple #"simple.txt" -L.
./Debug/main.cpp.o: In function `main':
C:/Users/joka0958/Desktop/wtp/compiledwtp/simple/main.cpp:7: undefined reference to `s1_s2_est(UnitProcess*)'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[1]: [Debug/simple] Error 1
mingw32-make.exe: [All] Error 2
simple.mk:78: recipe for target 'Debug/simple' failed
mingw32-make.exe[1]: Leaving directory 'C:/Users/joka0958/Desktop/wtp/compiledwtp/simple'
Makefile:4: recipe for target 'All' failed
2 errors, 1 warnings
So the question is: Why am I getting an undefined reference?
I realize this is one of those errors that probably masks another problem, but I have really exhausted all possibilities, in my mind, of what could be causing the problem. Note that this is part of a larger project where many other functions compile and link properly.
By the way I am using Codelite with the MinGW compiler on Windows 10.
I'm sorry for all the consternation this question caused. It turns out that there was C++-specific functions within this file, but because the file was named with a *.c, codelite defaulted to the C compiler to actually compile this particular source file. Once I changed the filename, the code compiled successfully. Thanks for all of your useful suggestions!

Redefinition different basic types => typedef

After to have been aware of the persons who had the same problem than mine, I still get this error :
error C2371: 'ST_ELLIPSE' : redefinition; different basic types
see declaration of 'ST_ELLIPSE'
C2371: 'ST_VECTEURS' : redefinition; different basic types
see declaration of 'ST_VECTEURS'
'ST_ROI' : redefinition; different basic types
see declaration of 'ST_ROI'
'ST_CONVERSION' : redefinition; different basic types
see declaration of 'ST_CONVERSION'
'ST_PARA_VISU' : redefinition; different basic types
see declaration of 'ST_PARA_VISU'
Here is the file:
#define MAX_VAL_VISU 245
#define MAX_VAL_VISU_SUPP 128
#define MAX_VAL_OVR_SUPP 116
#define VISU_SIZE_X 672
#define VISU_SIZE_Y 512
#define DELTA_ZONE 5
#define FLAG_RIEN 1
#define FLAG_ZOOM 2
#define FLAG_DEP 4
#define FLAG_STAT 8
#define FLAG_CONTRASTE 16
#define FLAG_ZONE 32
#define FLAG_OVR_WRITE 64
#define FLAG_OVR_EFF 128
#define FLAG_OVR_TEXTE 256
#define FLAG_ROI 512 // V2.0
// flag de suppression (& avec flag au dessus)
#define FLAG2_RIEN 0 // 0 aucune autres fenetres
#define FLAG2_ZOOM 0
#define FLAG2_DEP 0
#define FLAG2_STAT FLAG_CONTRASTE
#define FLAG2_CONTRASTE (FLAG_STAT | FLAG_ZONE | FLAG_ROI)
#define FLAG2_ZONE FLAG_CONTRASTE
#define FLAG2_OVR_WRITE (FLAG_ROI | FLAG_CONTRASTE)
#define FLAG2_OVR_EFF (FLAG_ROI | FLAG_CONTRASTE)
#define FLAG2_OVR_TEXTE 0
#define FLAG2_ROI FLAG_CONTRASTE
#define TYPE_MODIF_ZONE_RIEN 0 // pas de modification
#define TYPE_MODIF_ZONE_H 1 // definition de la ligne Haut
#define TYPE_MODIF_ZONE_B 2 // definition de la ligne BAS
#define TYPE_MODIF_ZONE_G 3 // definition de la ligne gauche
#define TYPE_MODIF_ZONE_D 4 // definition de la ligne droite
#define TYPE_MODIF_ZONE_P1 5 // definition du point haut/gauche
#define TYPE_MODIF_ZONE_P2 6 // definition du point bas/droite
#define TYPE_MODIF_ZONE_P3 7 // definition du point bas/gauche
#define TYPE_MODIF_ZONE_P4 8 // definition du point haut/droite
#define LUT_GRAY 0
#define LUT_COLOR1 1
#define LUT_COLOR2 2
#define LUT_FICHIER 3
#define LUT_SUPERPOSITION 4
#define NB_COULEUR 10
#define ROI_ZONE 0
#define NB_ROI 10
#define NB_UNITE 2
// structure
//***********
// V2.0
// ROI
typedef struct
{
// données de depart
double x1[NB_UNITE],y1[NB_UNITE],x2[NB_UNITE],y2[NB_UNITE],d2[NB_UNITE];
// donnee calculées
double d1[NB_UNITE];
double x11,y11,x22,y22;
// angle de rotation
double angle;
// origine
double ox,oy;
// position foyer
double fx1,fx2,fy1,fy2,dist;
// min max en X et en Y
int x_min,y_min,x_max,y_max;
}ST_ELLIPSE;
typedef struct
{
int nb;
double x[NB_UNITE][10],y[NB_UNITE][10];
}ST_VECTEURS;
#define ROI_RECTANGLE 0
#define CHAR_ROI_RECTANGLE "R"
#define ROI_ELLIPSE 1
#define CHAR_ROI_ELLIPSE "E"
#define ROI_VECTEURS 2
#define CHAR_ROI_VECTEURS "V"
typedef struct{
bool flag_def_zone;
int type_roi;
// rectangle
double x_zone[NB_UNITE],y_zone[NB_UNITE],dx_zone[NB_UNITE],dy_zone[NB_UNITE];
// ellipse
ST_ELLIPSE ellipse;
// vecteurs
ST_VECTEURS vecteurs;
}ST_ROI;
// V2.0
#define CONVERSION_ZONE 1 // indice dans ST_CONVERSION
// parametres de conversion pixel ->mm
typedef struct {
double x_pix,x_mm,y_pix,y_mm;
double coef_x;
double coef_y;
CString unite[2];
}ST_CONVERSION;
// V2.0
// parametres de la visu
typedef struct{
int x_zoom,y_zoom,m_zoom; // zoom
ST_ROI roi[NB_ROI]; // roi
int ind_conversion;
ST_CONVERSION coef_conversion[2]; // conversion pour stat pix->autre unité
}ST_PARA_VISU;`
Someone would have any ideas ?
Thanks per advance for your help !
Putting #pragma once at the top of each .h file is the way to do it if you don't mind using macros, and otherwise, the 'proper' way to do it is
#ifndef AWESOME_H
#define AWESOME_H
class Awesome
{
//awesome.h contents
};
#endif